简体   繁体   English

如何防止键盘和菜单同时显示?

[英]How can I prevent both the keyboard and the menu from being shown together?

Here's a screenshot of my application. 这是我的应用程序的屏幕截图。 When the search box is clicked, the soft-keyboard automatically pops up, which is fine, but, if I also press the "Menu" button, the menu appears on top of the soft-keyboard. 单击搜索框时,软键盘会自动弹出,这很好,但是,如果我也按“菜单”按钮,菜单会出现在软键盘的顶部。

How can I show the menu but collapse the SearchView if it is in focus and also hide the soft-keyboard. 如何显示菜单,但如果它处于焦点位置,则会折叠SearchView并隐藏软键盘。 I probably need to check and do something in the onPrepareOptionsMenu method of my Activity , right? 我可能需要检查并在我的ActivityonPrepareOptionsMenu方法中执行某些操作,对吧?

It doesn't cause any real harm to me but it seems like an ugly implementation to the user when this happens. 它不会对我造成任何真正的伤害,但在发生这种情况时,它似乎对用户来说是一种丑陋的实现。

在此输入图像描述

You can call the getCurrentFocus() method from the searchView or override onWindowFocusChanged(boolean hasWindowFocus) in your activity. 您可以从searchView调用getCurrentFocus()方法,也可以在活动中覆盖onWindowFocusChanged(boolean hasWindowFocus)

If that view is the searchview, then you can close the keyboard in this way: 如果该视图是搜索视图,则可以通过以下方式关闭键盘:

InputMethodManager imm = (InputMethodManager)getSystemService(
  Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(m_edittext.getWindowToken(), 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM