Android instance-Mobile security Defender (20)-Use shape shape, customize component borders, shapes, etc.

Source: Internet
Author: User

First, the goal.

1, implement the text component click event.

2. Implement components (TextView, etc.) to be displayed in shapes (rounded rectangles, ellipses, rings, etc.), or to add custom borders, gradients, and other properties. And can be combined with styles to implement the default, and to display different shapes according to the inferior process.

Default: Press:

Second, the code implementation.

1, TextView object with click event, you need to set the clickable property to True, and named Click event Name, that is, the OnClick property value is Resetwizard.

2, in the mobile phone anti-theft interface to achieve click event Processing, (that is, re-enter the "Setup Wizard" interface)

Click event handling code;

Re-enter the anti-Theft Setup wizard interface public void Resetwizard (view view) {Intent Intent =new Intent (securityactivity.this,setupwizard_ui_1. Class); StartActivity (intent); Finish ();}

2, Shape. (Refer to the reference documentation)

①. Create a new file (New-file) within the Drawable folder under the Res folder, name (gradient_box) and suffix. Xml.

②. Determine the XML version and encoding format in the new file. Build a <shape> tag to determine the namespace in its properties (xmlns:android= "Http://schemas.android.com/apk/res/android"

Android:shape= "Shape"), the shape's value can specify the desired shape (rectangle rectangle, Oval oval, straight line, annular ring)

 ③. Add additional labels to the <shape> tag to specify the style of the shape (such as corner corners, diameter, gradient gradient, and so on), specify the corresponding value in the properties of these style labels.

Shape Code:

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android"    android:shape= "Rectangle" >    <corners android:radius= "15dip"/><!--gradient--and    <gradient        android:endcolor= "#0000ff"        android:startcolor= "#ff0000"/>    <!--fixed color, conflict with gradients-        < Solid android:color= "#50000000"/>    <!--bezel-    <stroke android:width= "2dip"        android:color= "#000000"        android:dashwidth= "3dip"        android:dashgap= "5dip"/></shape>

3. Set the Background property in the component that needs to use shape shape, and find the new style file by @drawable.

4, out of the background property can be referenced, in the Drawable folder Style.xml can also refer to the style, so that the default, focus, press the different process to display different shape styles.

New Style code:

<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android ">    <item android:state_pressed=" true "        android:drawable=" @drawable/gradient_box_pressed " ></item>  <!--Press--        <item android:state_enabled= "true"        android:drawable= "@ Drawable/btn_default_selected "/> <!--focused--       <item android:drawable=" @drawable/gradient_box "/ > <!--Default---   </selector>

 

Android instance-Mobile security Defender (20)-Use shape shape, customize component borders, shapes, etc.

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.