[Android] Mobile Defender Customize dialog box layout

Source: Internet
Author: User

Mobile Anti-Theft page section

Click on the mobile phone anti-theft, to determine, if not set the password, display a Set Password dialog box, if the password has been set up, the Input Password dialog box

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

Customizing a layout file,dialog_setup_password.xml

The root layout width does not fill the screen

Internal controls, the width is smaller to make room, center alignment,android:gravity="center"

Two-side button, OK and cancel, linear layout horizontal orientation

Get alertdialog.builder object, via new Builder (), Parameters: Context Object

Call the Setview (view) method of the Builder object, parameter:view object, fill with the layout filler

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

Call the Show () method of the Builder Object

Homeactivity.java

    /*** Open the mobile Phone anti-theft dialog box*/    protected voidstartmobilesec () {String password=sp.getstring ("Password", "" "); //Set Password        if(textutils.isempty (password)) {Alertdialog.builder Builder=NewBuilder ( This); View View=view.inflate ( This, R.layout.dialog_setup_password,NULL);            Builder.setview (view);        Builder.show (); }Else{            //Enter Password                    }    }

Dialog_setup_password.xml

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "300DP"Android:layout_height= "Wrap_content"android:gravity= "Center_horizontal"android:orientation= "vertical" >    <TextViewAndroid:background= "#669933"Android:textcolor= "#fff"Android:layout_width= "Match_parent"Android:layout_height= "40DP"android:gravity= "Center"Android:text= "Set Password" />    <EditTextAndroid:layout_width= "290DP"Android:layout_height= "Wrap_content"Android:hint= "Please enter password"/>    <EditTextAndroid:layout_width= "290DP"Android:layout_height= "Wrap_content"Android:hint= "Please Confirm password"/>    <RelativelayoutAndroid:layout_margintop= "10DP"Android:layout_marginbottom= "10DP"android:gravity= "Center_horizontal"Android:layout_width= "200DP"Android:layout_height= "Wrap_content">        <ButtonAndroid:layout_alignparentleft= "true"Android:background= "#2aabd2"Android:textcolor= "#fff"Android:layout_width= "Wrap_content"Android:layout_height= "40DP"Android:text= "Confirm"/>        <ButtonAndroid:layout_alignparentright= "true"Android:background= "#eb9316"Android:textcolor= "#fff"Android:layout_width= "Wrap_content"Android:layout_height= "40DP"Android:text= "Cancel"/>    </Relativelayout></LinearLayout>

[Android] Mobile Defender Customize dialog box layout

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.