Hide keyboard when submitting search or select search suggestion

I have an action bar search widget that also offers a search suggestion. When a user enters a query and sends it or selects a sentence to search, the keyboard does not disappear. How can I solve this problem?

I was not able to figure out how to hide the keyboard when searching or selecting an offer.

Thank.

+5
source share
2 answers

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 example project .

+9
source

,

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

}

GoodLuck!!

+2

All Articles