0

I have a dialog box in my Android app; it is the only EditText control on the dialog (the others are spinners and buttons), and so it gets focus when the dialog is shown. This prevents the on-screen keyboard from ever showing up, meaning you can't easily enter any text into the box unless you have a hardware keyboard.

I believe (but I couldn't swear to it) that this is because the control starts with focus, and the system check as to whether to show the keyboard or not happens in the onfocus event. Is there any way the programmatically show the on-screen keyboard?

4

1 回答 1

1

In order to implement the ability to force the keyboard open when the user presses a button on the screen then the following should help.

InputMethodManager inputMethManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethManager.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);

However an alternative to help regain focus of the dialog window can be found below. This code should open the software keyboard for you by resetting any flags initially set by AlertDialog. This code should be placed after the creation of the dialog window.

dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
于 2013-08-12T21:02:39.837 回答