Custom exit pop-up boxes are not very common in applications. We often see them in games. Next, let's take a look at how it is implemented. First, we define a method to call this method when the user clicks to exit.
1 Private Void Dialog (){ 2 Final Alertdialog DLG = New Alertdialog. Builder ( This ). Create (); 3 DLG. Show (); 4 Window window = DLG. getwindow (); 5 Window. setcontentview (R. layout. Talk ); 6 Button OK = (Button) window. findviewbyid (R. Id. btn_ OK ); 7 OK. setonclicklistener ( New View. onclicklistener (){ 8 Public Void Onclick (view v ){ 9 Main. This . Finish (); 10 } 11 }); 12 Button cancel = (Button) window. findviewbyid (R. Id. btn_cancel ); 13 Cancel. setonclicklistener ( New View. onclicklistener (){ 14 Public Void Onclick (view v ){ 15 DLG. Cancel (); 16 } 17 }); 18 }
This is not much different from the normal pop-up box. You can use these two sentences to get the custom shape of the pop-up box.
Window window = DLG. getwindow (); window. setcontentview (R. layout. Talk );
For example:
So far, the design of the custom pop-up box has been completed.