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.
Asked
Active
Viewed 1.2k times
11
-
Check this link: http://stackoverflow.com/questions/14851964/android-searchview-onclick – Lokesh Sep 23 '13 at 11:10
-
possible duplicate of [Close/hide the Android Soft Keyboard](http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard) – Jost Sep 23 '13 at 11:19
-
Check [this](http://stackoverflow.com/questions/16184703/unable-to-hide-the-virtual-keyboard-of-searchview-iconfiedbydefaultfalse?answertab=votes#tab-top) also – nmxprime Jun 20 '14 at 12:46
-
possible duplicate of [How to dismiss keyboard in Android Honeycomb searchView](http://stackoverflow.com/questions/7409288/how-to-dismiss-keyboard-in-android-honeycomb-searchview) – matiash Feb 02 '15 at 20:25
-
why did you not choose this answer http://stackoverflow.com/a/20867923/4548520 ? it's correct one – user25 Sep 08 '16 at 11:56
3 Answers
46
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

Konstantin
- 174
- 7