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 ;