I want to hide soft keyboard after AlertDialog dismiss, but it's still visible. Here is my code:
alert = new AlertDialog.Builder(MyActivity.this); imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); alert.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); } });
Hiding the Soft Keyboard Programmatically You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field. This will force the keyboard to be hidden in all situations.
To hide keyboard, use the following code. InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); inputMethodManager. hideSoftInputFromWindow(v. getApplicationWindowToken(),0);
In Manifest xml
android:windowSoftInputMode="stateAlwaysHidden"
It will automatically hide soft keyboard on Dismiss of
Dialog
I met the same problem. Solved it by doing like this. It doesn't need any reference:
imm.hideSoftInputFromWindow(getWindow().getDecorView() .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
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