How to hide android keyboard in search view

末鹿安然 提交于 2019-12-09 15:12:01

问题


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.


回答1:


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

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



回答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




回答3:


you can hide it by

mSearchView.setIconified(true); 


来源:https://stackoverflow.com/questions/18957396/how-to-hide-android-keyboard-in-search-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!