Hide keyboard when a search is submitted or a search suggestion is chosen

半城伤御伤魂 提交于 2019-12-07 04:48:33

问题


I have a action bar search widget that offers search suggestion too. When the user types in a query and submits it or chooses a search suggestion, the keyboard doesn't disappear. How can I resolve this issue?

I haven't been able to figure out how to hide the keyboard upon search submit or suggestion choose.

Thank you.


回答1:


To hide the input method editor, use InputMethodManager:

  InputMethodManager imm=
      (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);

  imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

You can use this from onEditorAction(), for example, as shown in this sample project.




回答2:


I have just face to the same problem, and this way to hide keyboard after search

  @Override
 public boolean onQueryTextSubmit(String query) {
   searchView.clearFocus();
 return true;

}

GoodLuck !!



来源:https://stackoverflow.com/questions/12330969/hide-keyboard-when-a-search-is-submitted-or-a-search-suggestion-is-chosen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!