Android-click the button in the dialog box to not close the dialog box. android button
Sometimes I do not need to click the button for some detection, but do not want to close the dialog box (the system click any button by default to close the dialog box). The solution is as follows: add the following code under the click event:
Java code
- Try
- {
- Field field = dialog. getClass ()
- . GetSuperclass (). getDeclaredField (
- "MShowing ");
- Field. setAccessible (true );
- // Set the mShowing variable to false, indicating that the dialog box is closed.
- Field. set (dialog, false );
- Dialog. dismiss ();
- }
- Catch (Exception e)
- {
- }
Click the button to add the above Code to the Event code, and the button will no longer be able to close the dialog box. To close the dialog box, set mShowing to true. Note that setting the mShowing variable in one button also affects the function of closing the dialog box of another button. Therefore, you need to set the mShowing variable value in the click event of each button.