[英]How to make Android Soft keyboard showing or hiding listener better
I have seen a lot of questions about the solution for the soft keyboard show/hide listener. 我已经看到很多关于软键盘显示/隐藏监听器解决方案的问题。
I think this solution is great.But actually it is not working.So bad. 我认为这个解决方案很棒。但实际上它不起作用。太糟糕了。 Listen for keyboard show or hide event in android
在android中听取键盘显示或隐藏事件
Finally,I used this solution.But I think this solution is Just a temporary solution.We don't know 200dp represents soft keyboard correctly. 最后,我使用了这个解决方案。但我认为这个解决方案只是一个临时解决方案。我们不知道200dp正确代表软键盘。 How to check visibility of software keyboard in Android?
如何检查Android中软件键盘的可见性?
I want EditText and Textview which is below EditText both are on the top of soft keyboard, when soft keyboard is showing. 当软键盘显示时,我希望EditText和Textview下面的EditText都位于软键盘的顶部。 And I hope EditText and TextView(The Parent layout is LinearLayout) are not always align parent bottom ,so ... android:windowSoftInputMode="adjustresize" is not appropriate.
而且我希望EditText和TextView(Parent布局是LinearLayout)并不总是对齐父底部,所以... android:windowSoftInputMode =“adjustresize”是不合适的。
I think adjustPan is great but it only let EditText on the top when EditText is on focus.I want both them on top.T_T Help me! 我认为adjustPan很棒但是当EditText处于焦点时它只让EditText在顶部。我希望它们都在顶部.T_T帮助我! Thanks a lot.
非常感谢。
To know if the keyboard is hidden or visible, I use this code: 要知道键盘是隐藏还是可见,我使用以下代码:
view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
view.getWindowVisibleDisplayFrame(r);
if (view.getRootView().getHeight() - (r.bottom - r.top) > 500) { // if more than 100 pixels, its probably a keyboard...
onKeyboardShow();
} else {
onKeyboardHidden();
}
}
});
onKeyboardShow & onKeyboardHidden functions are my own which then do what's needed. onKeyboardShow&onKeyboardHidden函数是我自己的函数,然后执行所需的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.