Ask Questions

How to hide the Android Soft Keyboard

The virtual keyboard can be hidden using the InputMethodManager.

Method 1

Java Code

View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);

Kotlin Syntax

val view = this.currentFocus
view?.let { v ->
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
imm?.let { it.hideSoftInputFromWindow(v.windowToken, 0) }

Method 2

This is one of the second method to hide soft keyboard.

InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

Method 3

If both the above method does not work, than try the below code

protected void hideSoftKeyboard(EditText input) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);

Leave a Reply

Your email address will not be published. Required fields are marked *