In the android custom dialog box, EditText cannot bring up the input method solution. androidedittext

Source: Internet
Author: User

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,

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.