如何检测 android window 上的键盘 - Titanium Appcelerator
How to detect the keyboard on the android window - Titanium Appcelerator
我需要一些东西来验证 android 应用程序 window 中键盘的存在...问题是我无法测试焦点/模糊输入,并且需要那个检查键盘...我看到官方文档 Appcelerator 并且此功能仅适用于 iOS ...有人有解决方案吗?
KeyboardVisible 属性 iOS:
http://docs.appcelerator.com/platform/latest/#!/api/Titanium.App-property-keyboardVisible
没有任何直接的方法可以做到这一点。但有些技巧可能会奏效。试试这个。
final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
... do something here
}
}
});
As you can see in the official docs 没有检测键盘是否可见的本机方法;如果您需要在用户打开 window 时显示键盘,请向 'open' 和 'resume' 添加监听器(这个来自 activity,而不是 window,并且当你的应用程序从后台转到前台时也会被触发)对于一个专注于你的领域的功能,如果你需要知道键盘何时打开以更改布局,android 已经尝试适应它适合你(在这种情况下,将所有内容都放在滚动视图中)。
在 iOS 您可以收听 keyboardframechanged event. For Android, you might be able to use one of these modules。
我需要一些东西来验证 android 应用程序 window 中键盘的存在...问题是我无法测试焦点/模糊输入,并且需要那个检查键盘...我看到官方文档 Appcelerator 并且此功能仅适用于 iOS ...有人有解决方案吗?
KeyboardVisible 属性 iOS:
http://docs.appcelerator.com/platform/latest/#!/api/Titanium.App-property-keyboardVisible
没有任何直接的方法可以做到这一点。但有些技巧可能会奏效。试试这个。
final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
... do something here
}
}
});
As you can see in the official docs 没有检测键盘是否可见的本机方法;如果您需要在用户打开 window 时显示键盘,请向 'open' 和 'resume' 添加监听器(这个来自 activity,而不是 window,并且当你的应用程序从后台转到前台时也会被触发)对于一个专注于你的领域的功能,如果你需要知道键盘何时打开以更改布局,android 已经尝试适应它适合你(在这种情况下,将所有内容都放在滚动视图中)。
在 iOS 您可以收听 keyboardframechanged event. For Android, you might be able to use one of these modules。