How does android make the pop-up dialog box disappear? android dialog box
Builder builder = new AlertDialog. Builder (this );
Builder. setTitle (android. R. string. dialog_alert_title)
. SetIcon (android. R. drawable. ic_dialog_info)
. SetPositiveButton (android. R. string. OK,
New OnClickListener (){
Public void onClick (DialogInterface dialog,
Int which ){
// Do not disappear
Try {
Java. lang. reflect. Field field = dialog
. GetClass (). getSuperclass ()
. GetDeclaredField ("mShowing ");
Field. setAccessible (true );
Field. set (dialog, false );
} Catch (Exception e ){
E. printStackTrace ();
}
}
})
. SetNegativeButton (android. R. string. no,
New OnClickListener (){
Public void onClick (DialogInterface dialog,
Int which ){
// Disappear
Try {
Java. lang. reflect. Field field = dialog
. GetClass ()
. GetSuperclass ()
. GetDeclaredField ("mShowing ");
Field. setAccessible (true );
Field. set (dialog, true );
} Catch (Exception e ){
E. printStackTrace ();
}
Dialog. dismiss ();
}
}). Show ();
After testing, we found that the dialog box disappears if you click a place other than "OK", but if you click "OK" and then click a place other than the dialog box, it will not disappear.