[Android] mobile guard custom dialog box layout, android guard

Source: Internet
Author: User

[Android] mobile guard custom dialog box layout, android guard

Mobile phone anti-theft page

Click anti-theft on the mobile phone to determine whether to set a password. If no password is set, a dialog box is displayed. If a password has been set, the Enter Password dialog box is displayed.

The password is stored in SharedPreferences, and the data is retrieved for judgment.

 

Customize a layout file, dialog_setup_password.xml

Root layout width should not be full of Screen

Internal control. The width must be smaller and the center is aligned. android: gravity = "center"

Two side-by-side buttons, OK and cancel, linear layout horizontal orientation

 

Obtain the AlertDialog. Builder object, and use new Builder (). Parameter: context object

Call the setView (view) method of the Builder object. The parameter is a View object, which is filled by the layout filler.

Call the View. inflate (context, resource, root) method to convert the layout file into a View object, context, resource, and root

Call the show () method of the Builder object

 

HomeActivity. java

 

/*** Open the mobile phone anti-theft dialog box */protected void startMobileSec () {String password = sp. getString ("password", ""); // set the password if (TextUtils. isEmpty (password) {AlertDialog. builder builder = new Builder (this); View view = View. inflate (this, R. layout. dialog_setup_password, null); builder. setView (view); builder. show () ;}else {// enter the password }}

 

Dialog_setup_password.xml

<? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "300dp" android: layout_height = "wrap_content" android: gravity = "center_horizontal" android: orientation = "vertical"> <TextView android: background = "#669933" android: textColor = "# fff" android: layout_width = "match_parent" android: layout_height = "40dp" android: gravity = "center" android: text = "set password"/> <EditText android: layout_width = "290dp" android: layout_height = "wrap_content" android: hint = "Enter Password"/> <EditText android: layout_width = "290dp" android: layout_height = "wrap_content" android: hint = "Please confirm password"/> <RelativeLayout android: layout_marginTop = "10dp" android: layout_marginBottom = "10dp" android: gravity = "center_horizontal" android: layout_width = "200dp" android: layout_height = "wrap_content"> <Button android: layout_alignParentLeft = "true" android: background = "#2aabd2" android: textColor = "# fff" android: layout_width = "wrap_content" android: layout_height = "40dp" android: text = "OK"/> <Button android: layout_alignParentRight = "true" android: background = "# eb9316" android: textColor = "# fff" android: layout_width = "wrap_content" android: layout_height = "40dp" android: text = "cancel"/> </RelativeLayout> </LinearLayout>

 

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.