androidkeyboardhideandroid-softkeyboardsoft-keyboard

Hide soft keyboard after dialog dismiss


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);
    }
});

Solution

  • In Manifest xml

    android:windowSoftInputMode="stateAlwaysHidden"
    

    It will automatically hide soft keyboard on Dismiss of Dialog