How to Use Shape of Android control series

Source: Internet
Author: User

If you are not satisfied with the UI control provided by the Android system, you can try the custom control. Let's take the Button as an example, android has previously written the Android Button control beautification method, which mentions the xml selector structure. Of course, in addition to using images such as drawable, the Android Development Network talked about the custom image shape method today. For the Button control Android, the following attributes are supported: shape, gradient, stroke, corners, etc.

Copy codeThe Code is as follows: Let's take the selector of the current system Button as an example:
  
<Android: startColor = "# ff8c00"
Android: endColor = "# FFFFFF"
Android: angle = "270" type = "parmname" text = "parmname"/>
<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 shape is defined as gradient. In gradient, the startColor attribute is the starting color, endColor is the color of the gradient, and the angle below is the angle. Next, stroke can be understood as the edge, corners is the corner. Here the radius attribute is the radius, and finally the relative position attribute padding.
The complete definition of a Button can beCopy codeThe Code is as follows:
<Xmlns: android = "http://schemas.android.com/apk/res/Android">
  
<Android: startColor = "# ff8c00"
Android: endColor = "# FFFFFF"
Android: angle = "270" type = "parmname" text = "parmname"/>
<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" type = "parmname" text = "parmname"/>
<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" type = "parmname" text = "parmname"/>
<Android: width = "2dp"
Android: color = "# fad3cf"/>
<Android: radius = "2dp"/>
<Android: left = "10dp"
Android: top = "10dp"
Android: right = "10dp"
Android: bottom = "10dp"/>

  
  
Note: The main difference between the preceding items is that when state_pressed is pressed or state_focused is used to obtain the focus, Dangdang determines the type of the item to be displayed. items without the state_xxx attribute can be considered as in the regular 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.