Solution 1:

In Manifest xml

android:windowSoftInputMode="stateAlwaysHidden"

It will automatically hide soft keyboard on Dismiss of Dialog

Solution 2:

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

Solution 3:

I had a similar problem when closing an alert dialog. This seems to do the trick for me.

Inside your DialogFragment

public static void closeKB(final View view) 
{
    caller.postDelayed(new Runnable() {
        @Override
        public void run() {
            InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }, 1);
}

@Override
public void onDismiss(DialogInterface dialog)
{
    super.onDismiss(dialog);
            View view = getActivity().getCurrentFocus();
    if (view != null)
    {
        closeKB(view);
    }
}

Solution 4:

I use this method:

IBinder token = searchTextEntry.getWindowToken();
( ( InputMethodManager ) getSystemService( Context.INPUT_METHOD_SERVICE ) ).hideSoftInputFromWindow( token, 0 );

Where searchTextEntry is the name of my EditText reference.

Solution 5:

This works! This will close the keyboard after dialog dismiss

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