How To Hide Keyboard On Dialog Dismiss
I have an Activity with single Fragment on it. There is one EditText on the fragment. The keyboard is popping up as soon the fragment is shown, however I managed to block it settin
Solution 1:
In my case I used method:
publicstaticvoidcloseInput(final View caller) {
caller.postDelayed(newRunnable() {
@Overridepublicvoidrun() {
InputMethodManagerimm= (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
Solution 2:
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
Solution 3:
in BaseDialog.java
protectedvoidhideSoftKeyboard() {
InputMethodManager imm = (InputMethodManager) this.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isActive()) {
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
}
Solution 4:
In my case I was using:
android:windowSoftInputMode="adjustPan|stateVisible"
I deleted stateVisible
:
android:windowSoftInputMode="adjustPan"
And onDismiss()
, no need to call hideSoftInput
method.
Solution 5:
In my case, solution was to put keyboard hide in dialog dismiss
dialog.setOnDismissListener(newDialogInterface.OnDismissListener() {
@OverridepublicvoidonDismiss(DialogInterface dialog) {
Viewview= activity.getCurrentFocus();
if (view != null) {
InputMethodManagerinputManager= (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
});
Post a Comment for "How To Hide Keyboard On Dialog Dismiss"