Common methods:
Settitle: Setting a title for a dialog box
SetIcon: Setting icons for dialog boxes
Setmessage: Setting Content for dialog boxes
Setview: Setting Custom styles for dialog boxes
Setitems: A list of Settings dialog boxes to display, typically used to display several commands
Setmultichoiceitems: Used to set the dialog box to display a series of check boxes
Setneutralbutton: Normal button
Setpositivebutton: Add "Yes" button to the dialog box
Setnegativebutton: Dialog box Add "No" button
Create: Creating dialog box
Show: Show dialog box
First, the simple Alertdialog
Below, create a simple alertdialog and display it:
New Alertdialog.builder (Getapplicationcontext ())
. Settitle ("Confirm")
. SetIcon (R.drawable.ic_launcher)
. Setmessage ("Are you sure you want to end the application?" ")
. Show ();
Second, with the button Alertdialog
The example above is very simple, so let's add a few buttons to this alertdialog,
Prompt for delete Operation dialog box
New Alertdialog.builder (Getapplicationcontext ())
. Settitle ("Confirm")
. SetIcon (R.drawable.ic_launcher)
. Setmessage ("Are you sure you want to end the application?" ")
. Setpositivebutton ("OK", new Dialoginterface.onclicklistener () {
public void OnClick (Dialoginterface dialog, int which) {
Finish ();
}
})
. Setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {
public void OnClick (Dialoginterface dialog, int which) {
No action is taken when the user taps this button
}
})
. Show ();
Using the Alertdialog.builder class to create a dialog box