Hide soft keyboard after dialog dismiss

Dmytro Zarezenko picture Dmytro Zarezenko · Jul 24, 2012 · Viewed 33.6k times · Source

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

Answer

Rajeshwar picture Rajeshwar · Dec 14, 2013

In Manifest xml

android:windowSoftInputMode="stateAlwaysHidden"

It will automatically hide soft keyboard on Dismiss of Dialog