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);