简体   繁体   中英

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. I probably need to check and do something in the onPrepareOptionsMenu method of my Activity , right?

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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