Android Development Learning Note-Customize dialog box

Source: Internet
Author: User

The System default dialog box can only display simple title content and buttons, and if you want to be more realistic, you will need to customize the dialog box, the following is the way to customize the dialog box.

1. Define the template of the dialog box first

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "300DP"Android:layout_height= "Match_parent"android:orientation= "vertical" >        <TextViewAndroid:id= "@+id/tv_title"Android:layout_width= "300DP"Android:layout_height= "30DP"android:textsize= "22SP"Android:text= "Set Center"android:gravity= "Center"/><EditTextAndroid:id= "@+id/ed_password"Android:layout_width= "300DP"Android:layout_height= "50DP"android:textsize= "22SP"Android:hint= "Enter Password"    /><EditTextAndroid:id= "@+id/ed_re_password"Android:layout_width= "300DP"Android:layout_height= "50DP"android:textsize= "22SP"Android:hint= "Re-enter password"    /><LinearLayoutAndroid:layout_height= "Wrap_content"Android:layout_width= "300DP"android:orientation= "Horizontal"android:gravity= "Center_horizontal"    >        <ButtonAndroid:id= "@+id/btn_ok"Android:text= "OK"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"        />     <ButtonAndroid:id= "@+id/btn_cancel"Android:text= "Cancel"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"        /></LinearLayout></LinearLayout>

2. The dialog will then be re-rendered using the dialog box template.

New Builder (this);                 = View.inflate (mainactivity.  thisnull);        Dialog.setview (view);        Dialog.show ();

3, through the above settings can be customized dialog box

Android Development Learning Note-Customize dialog box

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.