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 setting in the manifest android:windowSoftInputMode="stateHidden"
However, there also is a button, which opens a dialog with another EditText.
I have a method that automatically closes the keyboard on dialog dismiss.
public static void closeInput(final View caller) {
caller.post(new Runnable() {
@Override
public void run() {
InputMethodManager imm = (InputMethodManager) caller.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(caller.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
}
});
}
The method is not a pretty hack and there is something wrong about it. Dialog's EditText
has inputType="numberDecimal"
. The closeInput()
seems to be not closing the keyboard, only changing it to the default alphabetical state.
What is going on here?
You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow , passing in the token of the window containing your focused view. This will force the keyboard to be hidden in all situations.
You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field. This will force the keyboard to be hidden in all situations.
You must have an EditText in your layout and that need to extent EditText base class. then Override onKeyPreIme() method, and return True. Now your keyboard will be always visible and can't be dismissed by Back key.
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
In my case I was using:
android:windowSoftInputMode="adjustPan|stateVisible"
I deleted stateVisible
:
android:windowSoftInputMode="adjustPan"
And onDismiss()
, no need to call hideSoftInput
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With