11

I've used search view in my application. I wonder how to hide the keyboard when i hit the search button on the search view? I have to use the back button to view the results.

Robin Qiu
  • 5,521
  • 1
  • 22
  • 19
gie
  • 111
  • 1
  • 1
  • 3
  • Check this link: http://stackoverflow.com/questions/14851964/android-searchview-onclick – Lokesh Sep 23 '13 at 11:10
  • possible duplicate of [Close/hide the Android Soft Keyboard](http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard) – Jost Sep 23 '13 at 11:19
  • Check [this](http://stackoverflow.com/questions/16184703/unable-to-hide-the-virtual-keyboard-of-searchview-iconfiedbydefaultfalse?answertab=votes#tab-top) also – nmxprime Jun 20 '14 at 12:46
  • possible duplicate of [How to dismiss keyboard in Android Honeycomb searchView](http://stackoverflow.com/questions/7409288/how-to-dismiss-keyboard-in-android-honeycomb-searchview) – matiash Feb 02 '15 at 20:25
  • why did you not choose this answer http://stackoverflow.com/a/20867923/4548520 ? it's correct one – user25 Sep 08 '16 at 11:56

3 Answers3

46

Here is a similar question: How to dismiss keyboard in Android SearchView?

  @Override
  public boolean onQueryTextSubmit(String query) {
      // Do search.
      searchView.clearFocus();
      return true;
  }
Community
  • 1
  • 1
Robin Qiu
  • 5,521
  • 1
  • 22
  • 19
2

Try this code:

private void hideKeyboard(){
    InputMethodManager inputManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
    inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}

call it on search button click listener

Konstantin
  • 174
  • 7
0

you can hide it by

mSearchView.setIconified(true); 
Zahra.HY
  • 1,684
  • 1
  • 15
  • 25