Custom dialog in Android

Source: Internet
Author: User

Code:

/** * Popup Set Anti-Theft Password dialog box */private void Showsetuppwddialog () {//popup dialog box Builder Builder = new Builder (this);//fill in a layout file for the current dialog box// TODO What this here stands for? Homeactivityview view = View.inflate (this, r.layout.dialog_setup_password, null);//Get Input password and Confirm password final EditText et_ Password = (EditText) View.findviewbyid (R.id.et_password); final EditText et_password_confirm = (EditText) View.findviewbyid (r.id.et_password_confirm);//To Confirm and cancel the dialog box two buttons to set the listener, note that the button is defined in the Dialog_setup_password.xml, The This here represents Homeactivitybutton Bt_ok = (button) View.findviewbyid (R.id.ok);//In the popup dialog box, find Buttonbutton bt_cancel = (Button) View.findviewbyid (R.id.cancel); Bt_ok.setonclicklistener (new Onclicklistener () {//When this method is triggered when a click is confirmed, That is, set the anti-theft password @overridepublic void OnClick (View v) {//To determine the input password, and the SP to save//Get the password string password = Et_password.gettext (). ToString (). Trim (); String password_confirm = Et_password_confirm.gettext (). toString (). Trim ();//empty, whether the sentence is equal if (Textutils.isempty (password ) {Toast.maketext (homeactivity.this, "Password cannot be empty!", 1). Show (); else if (Textutils.isempty (password_confirm) {Toast.maketext (homeactivity.this, "Confirm password cannot be empty!", 1). Show (); else if (!password_confirm.equals (password_confirm)) {Toast.maketext (homeactivity.this, "two times password inconsistent!", 1). Show ();} else{//Save Password Editor editor = Sp.edit (); Editor.putstring ("Password", Md5utils.encode (password)); Editor.commit (); Toast.maketext (Homeactivity.this, "set success!", 1). Show ()//Enter the home page of the anti-theft settings Intent Intent = new Intent (Homeactivity.this, Lostfindactivity.class); StartActivity (Intent);d Ialog.dismiss ();}}); Bt_cancel.setonclicklistener (New Onclicklistener () {//When this method is triggered when a hit is canceled, destroy the cue box @overridepublic void OnClick (View v) { Dialog.dismiss ();}}); /builder.setview (view);//dialog = Builder.show ();//To solve the problem of running the border raised by dialog in the Low version dialog = Builder.create ();// Set all surrounding spacing to 0//dialog.setview (view, Viewspacingleft, Viewspacingtop, Viewspacingright, Viewspacingbottom) Dialog.setview (view, 0, 0, 0, 0);d ialog.show ();}

Layout: Dialog_setup_password.xml

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" 300dip "android:background=" #ffffff "//Low version 2.3 adaptation
Android:gravity= "Center_horizontal" android:layout_height= "wrap_content" android:orientation= "vertical" > <textview android:textcolor= "#000000" android:textsize= "18sp" android:layout_width= "300dip" android:layout_height= "50dip" android:background= "#66ff6600" android:gravity= "Center" android:text= " Set password "/> <edittext android:id=" @+id/et_password "android:layout_width=" 280dip "android:layou t_height= "wrap_content" android:hint= "Please enter the password you want to set" android:inputtype= "Textpassword" > </EditText> <edittext android:id= "@+id/et_password_confirm" android:layout_width= "280dip" Android:layout_h eight= "wrap_content" android:hint= "Please enter the password you want to set again" android:inputtype= "Textpassword"/> <linearlayout Android:gravity= "Center_horizontal" android:layout_width= "300dip" android:layout_height= "wrap _content "Android: orientation= "Horizontal" > <button android:id= "@+id/ok" android:layout_width= "140dip" android:layout_height= "Wrap_content" android:text= "OK"/> <button android:id = "@+id/cancel" android:layout_width= "140dip" android:layout_height= "Wrap_content" Android : text= "Cancel"/> </LinearLayout></LinearLayout>

Custom dialog in Android

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.