Android Customization dialog box

Source: Internet
Author: User
Tags gettext

Android implements a custom dialog box effect:

Core code:

Package Com.example.diydialog;import Android.os.bundle;import android.app.activity;import Android.app.alertdialog;import Android.content.dialoginterface;import Android.content.dialoginterface.onclicklistener;import Android.view.menu;import Android.view.View;import Android.widget.edittext;import Android.widget.Toast; Public classMainactivity extends Activity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);    Setcontentview (R.layout.activity_main); } @Override Publicboolean Oncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true; }         Public voidBtn_dialog (View v) {alertdialog.builder Builder=NewAlertdialog.builder ( This); Builder.settitle ("User Login");        Builder.seticon (R.drawable.ic_launcher); Final View View=getlayoutinflater (). Inflate (R.layout.login,NULL);                Builder.setview (view); Builder.setpositivebutton ("Login",NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface arg0,intarg1) {                //TODO Auto-generated method stubsEditText ed1=(EditText) View.findviewbyid (R.ID.EDITTEXT1); EditText Ed2=(EditText) View.findviewbyid (R.ID.EDITTEXT2); String Ed11=Ed1.gettext (). toString (); String Ed22=Ed2.gettext (). toString (); Toast.maketext (mainactivity. This, ed11+"---"+ed22, Toast.length_short). Show ();                }        }); Builder.setnegativebutton ("Cancel",NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface arg0,intarg1) {                //TODO Auto-generated method stubsToast.maketext (mainactivity. This,"has been canceled", Toast.length_short). Show ();        }        });    Builder.show (); }    }

The layout file is relatively simple, it is not posted, you can add the corresponding buttons and text boxes according to the code.

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.