Reputation: 121
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.
Upvotes: 12
Views: 12357
Reputation: 5731
Here is a similar question: How to dismiss keyboard in Android SearchView?
@Override
public boolean onQueryTextSubmit(String query) {
// Do search.
searchView.clearFocus();
return true;
}
Upvotes: 47
Reputation: 184
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
Upvotes: 2