Android Learning Note: android dialog box

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.