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