Operating effect:
Method One
public void OpenDialog (View v) {//Opens a dialog//builder object Alertdialog.builder Builder = new Builder (this);//The Builder creates a dialog box Alertdialo G Alertdialog = Builder.create ();//The caption of the settings dialog alertdialog.settitle ("I am the dialog box");//Settings dialog box Contents Alertdialog.setmessage (" Do you really want to quit the program? ");//Settings Dialog Icon Alertdialog.seticon (r.drawable.ic_launcher); Alertdialog.setbutton (dialoginterface.button_positive , "OK", new Onclicklistener () {@Overridepublic void OnClick (dialoginterface dialog, int which) {//TODO auto-generated Meth Od stubtoast.maketext (mainactivity.this, "OK", Toast.length_long). Show ();}); Alertdialog.setbutton (dialoginterface.button_neutral, "neutral", new Onclicklistener () {@Overridepublic void OnClick ( Dialoginterface dialog, int which) {Toast.maketext (mainactivity.this, "neutral", Toast.length_long). Show ();}); Alertdialog.setbutton (Dialoginterface.button_negative, "Cancel", new Onclicklistener () {@Overridepublic void OnClick ( Dialoginterface dialog, int which) {Toast.maketext (Mainactivity.this, "Cancel", Toast.length_long). Show ();}); /Alertdialog must be set.Show ();}
Method 2
public void OpenDialog (View v) {new Alertdialog.builder (this). Settitle ("I am a dialog box"). Setmessage ("Do you really want to quit the program"). SetIcon ( R.drawable.ic_launcher). Setpositivebutton ("OK", new Onclicklistener () {@Overridepublic void OnClick (dialoginterface dialog, int which) {//TODO auto-generated method Stubtoast.maketext (mainactivity.this, "OK", Toast.length_long). Show () ;}}). Setneutralbutton ("neutral", new Onclicklistener () {@Overridepublic void OnClick (dialoginterface dialog, int which) { Toast.maketext (Mainactivity.this, "neutral", Toast.length_long). Show ();}}). Setnegativebutton ("Cancel", new Onclicklistener () {@Overridepublic void OnClick (dialoginterface dialog, int which) { Toast.maketext (Mainactivity.this, "Cancel", Toast.length_long). Show ();}}). Create (). Show (); }
Method 3 Create a new activity, set the theme theme in Androidmenifest.xmlandroid:theme= "@android: Style/theme.dialog"