EditText in the custom dialog box in Android cannot eject the IME solution

Source: Internet
Author: User

Strangely, if you use the native Alertdialog, you can always pop the input box by Setview (New EditText ()) method;

And in our custom alertdialog, often encounter the problem of input method, here I divided into 2 cases:

I. In activity, the EditText in custom Alertdialog does not play the input method

method One: In the inheritance Alertdialog, the OnCreate () method, set the following:

Requestwindowfeature (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
The reason for this is that by looking at Alertdialog's documentation, it defaults to this:

Requestwindowfeature (WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
The document says Alertdialog default task you do not need to interact with the input method, so set up a flag without edittext, and if you want to interact with the input method, set flag_not_focusable,

method Two: Inherit Dialog,dialog the default style is ugly, but you need to do 2 operations, which are done in the OnCreate method
First: Remove the black head:

Requestwindowfeature (window.feature_no_title);//Remove the black head
Second: Remove the black background:
GetWindow (). Setbackgrounddrawableresource (Android. r.color.transparent);//The only way to get rid of the black background


two. In fragment, the EditText in custom Alertdialog does not play the input method
In this case, the method in the activity is not possible.

I also tried to set the input method settings, such as:

GetWindow (). Setsoftinputmode (WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

Also in fragment and activity for the same setting, but also let Edittext.requestfocus (), but not all;

Also tried to click on the EditText, the use of Inputmethodmanager Force pop-up, still does not work;

I later added an empty EditText with Setview (new EditText ()) before the show () method call, because it was a custom alertdialog that had the layout we specified, so this empty

EditText is not displayed, this time will be able to pop up the dialog box, the specific reason is unclear, guess should still focus on the issue of Access,

EditText in the custom dialog box in Android cannot eject the IME solution

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.