2 Ways to Customize dialog boxes

Source: Internet
Author: User

1: Full Layout customization

                Layoutinflater Addblacknumberinflater = (layoutinflater) getsystemservice (Layout_inflater_service);                View view = Addblacknumberinflater.inflate (R.layout.alert_dialog_disagree_refund, NULL);                Final Alertdialog.builder Reasonbuilder = new Alertdialog.builder (saleorderdetailactivity.this);                Reasonbuilder.setview (view);                Final Dialog Dialog = Reasonbuilder.create ();                Dialog.show ();                Final EditText EditText = (EditText) View.findviewbyid (R.id.edit_reason);                Button CANCELBT = (button) View.findviewbyid (R.id.btn_cancel);                Button CONFIRMBT = (button) View.findviewbyid (r.id.btn_confirm); Confirmbt.setonclicklistener (New View.onclicklistener () {@Override public void Oncl                    Ick (View v) {toastutil.show (Saleorderdetailactivity.this, Edittext.gettext (). toString ());               } }); Cancelbt.setonclicklistener (New View.onclicklistener () {@Override public void oncli                    CK (View v) {Dialog.dismiss (); }                });


Alert_dialog_disagree_refund.xml:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:orientation=" vertical "android:layout_width=" Match_parent "Android    : layout_height= "match_parent" android:gravity= "center" android:background= "@color/white" > <textview style= "@style/lightgreycolor.largefont" android:layout_width= "Fill_parent" Android:paddi ng= "@dimen/padding_medium" android:gravity= "center" android:textcolor= "@color/cinnamomum" Android:tex t= "@string/refund_disagree"/> <view style= "@style/basestyle.line.divier" android:background= "@color /black "/> <edittext style=" @style/lightgreycolor.largefont "android:paddingbottom=" @dimen/margin_xx XLarge "android:paddingtop=" @dimen/margin_xxxlarge "android:minlines=" 2 "android:textcolor=" @color/te Xt_title "Android:layout_widTh= "fill_parent" android:gravity= "center" android:id= "@+id/edit_reason" android:hint= "@string/refund_ Disagree_reason "/> <view style=" @style/basestyle.line.divier "/> <linearlayout styl E= "@style/basestyle.fullwrap" android:id= "@+id/btn_layout" android:orientation= "Horizontal" > <B Utton android:layout_width= "fill_parent" android:layout_height= "Wrap_content" Android:lay            Out_margin= "0DP" android:background= "@color/white" android:paddingtop= "@dimen/margin_large" android:paddingbottom= "@dimen/margin_large" android:layout_weight= "1" android:id= "@+id/btn_cancel "Android:textcolor=" @color/title_color "android:text=" Cancel "/> <button Android            : layout_width= "fill_parent" android:layout_height= "wrap_content" android:layout_margin= "0DP" Android:paddingtop= "@dimen/margin_large "android:paddingbottom=" @dimen/margin_large "android:layout_weight=" 1 " Android:id= "@+id/btn_confirm" android:background= "@color/background_button_brown" Android:textcolo R= "@color/white" android:text= "OK"/> </LinearLayout></LinearLayout>




2: Partial layout customization

View container = Getlayoutinflater (). Inflate (r.layout.dialog_input, null);                Final EditText Inputet = (EditText) Container.findviewbyid (r.id.et_input);                New Alertdialog.builder (this). Settitle ("Bid purchase"). Setview (Container). Setpositivebutton (Android. R.string.ok, New Dialoginterface.onclicklistener () {                    @Override public                    void OnClick (Dialoginterface dialog, int which) {                        String s = Inputet.gettext (). toString (). Trim ();                        Toastutil.show (saleorderdetailactivity.this, s);                }). Setnegativebutton (Android. R.string.cancel, NULL). Create (). Show ();

Dialog_input.xml:

<?xml version= "1.0" encoding= "Utf-8"? ><framelayout    style= "@style/rosemary.line.light"    xmlns: Android= "http://schemas.android.com/apk/res/android"    android:padding= "@dimen/margin_standard" >    < EditText        android:id= "@+id/et_input"        style= "@style/rosemary.line"        android:maxlength=        " android:numeric= "integer" >        <requestFocus/>    </EditText></FrameLayout>






2 Ways to Customize dialog boxes

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.