The use of shape for the Android control series _android

Source: Internet
Author: User

If you're not satisfied with the UI controls that come with your Android system, you can try a custom control, and we'll take the button as an example, a long time ago Android123 wrote the Android button button control beautification method that mentions the selector constructs of XML. Of course, in addition to using images like Drawable, the Android web today talks about customizing the shape shapes, and supports the following properties on the button control Android shape, gradient, stroke, corners, and so on.

Copy Code code as follows:
Let's take the current system button selector as an example:
  
< android:startcolor= "#ff8c00"
Android:endcolor= "#FFFFFF"
android:angle= "270"/>
< android:width= "2DP"
Android:color= "#dcdcdc"/>
< android:radius= "2DP"/>
< android:left= "10DP"
android:top= "10DP"
android:right= "10DP"
android:bottom= "10DP"/>
 
 
For the above, the definition of this shape, respectively, is a gradient, in gradient the StartColor property is the beginning of the color, endcolor for the gradient end of the color, the following angle is the angle. Next is stroke can be understood as the edge, corners for the corner here Radius property is radius, and finally relative position attribute padding.
For a button The complete definition can be thought
Copy Code code as follows:
  
<xmlns:android= "Http://schemas.android.com/apk/res/Android" >
  
<android:startcolor= "#ff8c00"
Android:endcolor= "#FFFFFF"
android:angle= "270"/>
<android:width= "2DP"
Android:color= "#dcdcdc"/>
<android:radius= "2DP"/>
<android:left= "10DP"
android:top= "10DP"
android:right= "10DP"
android:bottom= "10DP"/>

<android:startcolor= "#ffc2b7"
Android:endcolor= "#ffc2b7"
android:angle= "270"/>
<android:width= "2DP"
Android:color= "#dcdcdc"/>
<android:radius= "2DP"/>
<android:left= "10DP"
android:top= "10DP"
android:right= "10DP"
android:bottom= "10DP"/>

<android:startcolor= "#ff9d77"
Android:endcolor= "#ff9d77"
android:angle= "270"/>
<android:width= "2DP"
Android:color= "#fad3cf"/>
<android:radius= "2DP"/>
<android:left= "10DP"
android:top= "10DP"
android:right= "10DP"
android:bottom= "10DP"/>

  
  
Tip, the difference between the above several item is mainly reflected in state_pressed press or state_focused gain focus, when to determine what type of display, and no state_xxx attributes of the item can be seen as normal state.

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.