Question

I have create an custom dialog by extending the Dialog class.

In my app i have an EditText and the user presses ok after he finishes from the action bar, so the keyboard is on. Then a CustomDialog saying everything went ok appears and on click i close the keyboard like this

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);

but the keyboard stays on. If i create a builder and do the same the keyboard hides. Also another clue is that the inputType of the edittext is number but when the dialog appears it becomes text.

Thank you for any advice or ideas.

Was it helpful?

Solution

You must add the following code in the costructor

getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

Often you will want to have a Dialog display on top of the current input method, because there is no reason for it to accept text. You can do this by setting the WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM window flag (assuming your Dialog takes input focus, as it the default) with the following code:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
     WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

Also found here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top