Android Customization dialog box

Source: Internet
Author: User

First you need a layout interface:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" match_parent "    android:o rientation= "vertical" >    <edittext android:layout_width= "match_parent" android:layout_height= "Wrap_ Content "         android:hint=" name "android:id=" @+id/alert_homephone_nameet "/>        <edittext android:layout_ Width= "Match_parent" android:layout_margintop= "12DP" android:layout_height= "wrap_content"        android:hint= "mobile phone number "Android:id=" @+id/alert_homephone_phoneet "        /></linearlayout>

This interface is the interface we need to display when we customize the dialog box.

Alertdialog.builder Builder =new Alertdialog.builder (this);          Layoutinflater inflater = Getlayoutinflater ();     View layout = inflater.inflate (R.layout.home_phone, null);     Builder.setview (layout);      Homephonenameet = (EditText) Layout.findviewbyid (r.id.alert_homephone_nameet);      Homephoneet = (EditText) Layout.findviewbyid (r.id.alert_homephone_phoneet);      Homephoneet.settext ("13195338922"); Homephonenameet.settext ("Lao Wang");     Builder.setpositivebutton ("OK", new Dialoginterface.onclicklistener () {@Overridepublic void OnClick (dialoginterface dialog, int which) {}});     Builder.setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {                 @Overridepublic void OnClick ( Dialoginterface dialog, int which) {Dialog.dismiss ();}        });
Builder.show ();    

Note that at the end do not forget show ().

Summary: The method is to customize a layout. It is then populated with Layoutinflater and then specified using the Alertdialog.builder Setview () method. Then call Show () and note the API description of the show () method:

Creates a with the AlertDialog arguments supplied to this builder Dialog.show() and ' s the dialog. That is, create a dialog and then display


Android Customization 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.