Home » Android » How to hide android keyboard in search view

How to hide android keyboard in search view

Posted by: admin May 14, 2020 Leave a comment

Questions:

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.

How to&Answers:

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

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

Answer:

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

Answer:

you can hide it by

mSearchView.setIconified(true);