How to hide android keyboard in search view

2020-07-06 04:27发布

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.

3条回答
狗以群分
2楼-- · 2020-07-06 04:47

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

查看更多
可以哭但决不认输i
3楼-- · 2020-07-06 04:59

you can hide it by

mSearchView.setIconified(true); 
查看更多
迷人小祖宗
4楼-- · 2020-07-06 05:02

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

  @Override
  public boolean onQueryTextSubmit(String query) {
      // Do search.
      searchView.clearFocus();
      return true;
  }
查看更多
登录 后发表回答