In the android custom dialog box, EditText cannot bring up the input method solution. androidedittext
It is strange that if you use the native AlertDialog and add an input box using the setView (new EditText () method, the input method will always pop up;
In our custom AlertDialog, we often encounter the problem that the input method cannot be displayed. Here I divide it into two situations:
1. In the Activity, the EditText in the Custom AlertDialog does not display the input method.
Method 1: In the inherited AlertDialog and onCreate () methods, set as follows:
requestWindowFeature(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
The reason is as follows:
requestWindowFeature(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
The document says that you do not need to interact with the input method for the default AlertDialog task, so you have set a FLAG without EditText. If you want to interact with the input method, set FLAG_NOT_FOCUSABLE,
Method 2: Inherit from Dialog. The default style of Dialog is ugly, but two operations are required. This operation is performed in the onCreate method.
First, remove the black head:
RequestWindowFeature (Window. FEATURE_NO_TITLE); // remove the black Header
Second, remove the black background:
GetWindow (). setBackgroundDrawableResource (android. R. color. transparent); // only in this way can the black background be removed.
2. In Fragment, the EditText in the Custom AlertDialog does not display the input method.
In this case, the method in the activity cannot work.
I also tried setting the input method, such:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
In fragment and activity, the same settings also make EditText. requestFocus (), but none of them work;
I also tried to use InputMethodManager to force the pop-up when I click EditText;
Later, before calling the show () method, I used setView (new EditText () to add an empty EditText. Since it is a custom AlertDialog, it has the layout we specified, so this empty
EditText is not displayed. the dialog box will pop up at this time. The reason is unknown. I guess it should be the problem of getting the focus,