Reputation: 33
I have a dialog containing an EditText (inputType="number"
). After the dialog is dismissed i would like to hide the keyboard, which is opened if the EditText of the dialog was in Focus at some point.
Now the thing is that i have an approach that works (at least on some Nexus Devices), except for Samsung Devices (S2, S3 at least).
final InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
On other devices the keyboard (only numbers) closes after the dialog.
On Samsung devices the keyboard just changes to a keyboard with all the letters (inputType="text")
, instead of the keyboard for inputType="numbers"
. I want it to close/hide instead.
I can not do something like
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
for the Activity in the background, because i need a keyboard there as well.
Does anyone know how to handle this Samsung specific problem?
Upvotes: 3
Views: 959
Reputation: 1645
I have no Samsung device to test my code, but I'm using the WindowToken from the EditText to hide the SoftKeyboard. My Code looks like this:
View focused = getCurrentFocus();
if (focused != null) {
InputMethodManager iM = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
iM.hideSoftInputFromWindow(focused.getWindowToken(), 0);
}
Hope it works :)
Upvotes: 1
Reputation: 22493
Use this code
InputMethodManager inputMethodManager=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
Upvotes: 4