【发布时间】:2012-03-30 08:46:13
【问题描述】:
有没有办法知道虚拟键盘在运行时被用户隐藏了。 在标记我重复的问题之前,请先了解我的问题,因为它看起来很重复,而且我还发现了很多与相关主题相关的问题。但没有找到任何答案。
我的问题是在某些事件发生期间,比如说方向改变,我需要知道用户是否最小化了键盘。以便我采取相应的措施。我试图非常具体地提出问题,即使任何解释都可以随意提问。任何帮助将不胜感激。在此先感谢 我的尝试
final View activityRootView = findViewById(R.id.ll_main_root);
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...
Toast.makeText(MainActivity.instance, "KeyBoarad" + value, Toast.LENGTH_LONG).show();
}
}
});
【问题讨论】:
标签: android android-virtual-keyboard