2016-04-22 50 views

回答

-2

没有任何直接的方式做到这一点。但一些诀窍可能是工作。尝试这个。

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 
    } 
    } 
}); 
+0

感谢您的回复朋友,但我正在使用Appcelerator Titanium(JS)构建我的应用程序...并非原生... –

1

As you can see in the official docs没有本地的方法来检测键盘是否可见;如果您需要在用户打开窗口时显示键盘,请将侦听器添加到“打开”和“恢复”(这是来自活动,而不是窗口,并且在您的应用从背景移动到如果你需要知道什么时候键盘打开来改变布局,android已经尝试为你调整它(在这种情况下,将所有内容放在滚动视图中)。