In the alertdialog dialog box in Android, click "disappear?

Source: Internet
Author: User

A problem encountered during development is that the dialog box disappears automatically when you touch the external edge of the dialog box. This problem is very tangled. I found that from Android 4.0, alertdialog has changed, that is, the dialog box automatically disappears outside the edge of the touch dialog box. I checked the source code and found a solution:

 

When studying its parent class, we found that we can set such an attribute to call these two methods only after alertdialog. Builder. Create ().

 

Method 1:

Setcanceledontouchoutside (false); when this method is called, it does not work outside the dialog box. Pressing the return key also takes effect.

Method 2:

Setcanceleable (false); when this method is called, it does not work outside the dialog box. Pressing the return key does not work either.

Both methods belong to the dialog method. You can refer to the source code.

 

The modified source code is as follows:

 

 Case   1 : Dismissdialog (  1  );  New Builder (splashactivity. This ). Settitle ( "  Prompt  " ). Setcancelable ( False  ). Setmessage (  "  An error occurred while obtaining software initialization information! \ N check whether the network is smooth.  "  ). Setpositivebutton ( "  Confirm  " , New  Onclicklistener () {@ override  Public   Void Onclick (dialoginterface dialog, Int  Which) {dialog. Dismiss (); splashactivity.  This  . Finish () ;}). Show (); Break ;

 

 

 

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.