gie
gie

Reputation: 121

How to hide android keyboard in search view

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.

Upvotes: 12

Views: 12357

Answers (3)

Zahra.HY
Zahra.HY

Reputation: 1692

you can hide it by

mSearchView.setIconified(true); 

Upvotes: 0

Robin Qiu
Robin Qiu

Reputation: 5731

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

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

Upvotes: 47

Konstantin
Konstantin

Reputation: 184

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

Upvotes: 2

Related Questions