If an edittext is currently focused and the user clicks outside of the DialogFragment; I want the on screen keyboard to disappear. I can get it to work for when the DialogFragment is dismissed this way:
InputMethodManager imm;
public View onCreateView(LayoutInflater inflator, ViewGroup container,
Bundle savedInstanceState) {
imm = (InputMethodManager)getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
...}
@Override
public void dismiss(){
imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
super.dismiss();
}
However, if I try the same thing for when it is canceled by touching outside of the dialogfragment, it will not work. I am trying to do this by overriding onCancel like so:
@Override
public void onCancel(DialogInterface dialog){
imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
super.onCancel(dialog);
}
The function is called when the outside touch event happens, but the keyboard is not removed.
onDismiss()
method in yourDialogFragment
and hide the keyboard from there. – Glantz