Is there a way to hide the virtual keyboard once I click a button in android? The keyboard originally pops up when the user touches an edittext component; I'd like it to close once a button is pushed.
To hide virtual keyboard try/use this
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(medtSearchQuery.getWindowToken(), 0);
Best Practice for hiding keyboard:
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
It will automatically receive the current focus and will hide keyboard. Doesn't matter how many EditText
views you have.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With