How to hide keyboard on dialog dismiss

In my case I used method:

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

It was refusing to work properly because of activity settings in Manifest, if I recall you can't have android:windowSoftInputMode="any_of_these" set


in BaseDialog.java

protected void hideSoftKeyboard() {
    InputMethodManager imm = (InputMethodManager) this.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm.isActive()) {
        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

From fragments onCreateView() method you can do this:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)

It will automatically hide soft keyboard on Dismiss of Dialog