Android provides us with a variety of dialog boxes, of which Alertdialog features are the most powerful and most commonly used. In addition, there are progressdialog,datepickerdialog and timepickerdialog.
the Alertdialog.builder class can help us create a dialog box conveniently.
The steps are as follows:
1. Create a alertdialog.builder object.
2. Call settitle (),setcustomtitle (),setIcon () and other methods to set the dialog title, icons, content, and so on.
3. call the Create () method of the Alertdialog.builder class for creating the alertdialog object that is called in the Alertdialog of the Show () method displays a dialog box.
The Settings dialog box contains the following methods:
Setmessage (): Set dialog box contents as simple text
Setitems (): Set dialog box contents as simple list item
Setsinglechoiceitems (): Set dialog box content as a single-selection list item
Setmultichoiceitems (): Set dialog box content as multi-select list box
Setadapter (): Set dialog box content as custom list item
Setview (): Set dialog box content to custom View
We can also use Setpositivebutton (),Setneutralbutton ( ) and Setnegativebutton () Sets the button for the dialog box.
If we set properties for Activity in the androidmanifest.xml file
Android:theme= "@android: Style/theme.material.dialog"
You can create a dialog-style window.
Popupwindow can also be used to create a dialog box with the following steps:
1. Call the constructor to create the Popuwindow object.
2. There are two display methods:
(1) Showasdropdown (View v) is displayed below the V component.
(2) Showatlocation () is displayed at the specified location.
3. Close the dismiss () method.
Datepickerdialog,timepickerdialog can create a dialog box with a selector, with the following steps:
1. Creating an object with a constructor
2. Binding listeners to Objects
ProgressDialog can create a dialog box with a progress bar, with the following steps:
1. Create the ProgressDialog object with the constructor .
2. Call various methods to set it.
3. Show it using the Show () method.
The methods that you can use to set up are the following:
Setindeterminate (Boolean): Sets whether the dialog progress bar displays progress values.
Setmax (int): Sets the maximum value of the dialog box progress bar.
Setmessage (charsequence): Sets the message displayed in the dialog box.
setprogress (int): Sets the progress value of the progress bar in the dialog box.
Setprogressstyle (int): Sets the style of the progress bar for the dialog box.
Android Learning Note: android dialog box