Use shape to beautify the android Control

Source: Internet
Author: User
In addition to using images such as drawable, we can talk about the custom image shape method today. The following attributes such as shape, gradient, stroke, and corners are supported for the button control android.

Let's take the selector of the current system button as an example:

<Shape>
<Gradient
Android: startcolor = "# ff8c00"
Android: endcolor = "# ffffff"
Android: angle = "270" type = "parmname" text = "parmname"/>
<Stroke
Android: width = "2dp"
Android: color = "# dcdcdc"/>
<Corners
Android: radius = "2dp"/>
<Padding
Android: Left = "10dp"
Android: Top = "10dp"
Android: Right = "10dp"
Android: Bottom = "10dp"/>
</Shape>

For the above, the shape is defined as gradient. In gradient, the startcolor attribute is the starting face color.
Color, endcolor is the color of the gradient end, and the angle below is the angle. Next, stroke can be understood as the edge, and corners is the corner. Here, the radius attribute is half.
Path, and finally the relative position attribute padding.

The complete definition of a button can be

<? XML version = "1.0" encoding = "UTF-8"?> <Selector xmlns: Android = "http://www.norkoo.com"> <item Android: state_pressed = "true"> <shape> <gradient Android: startcolor = "# ff8c00" Android: endcolor = "# ffffff" Android: angle = "270"/> <stroke Android: width = "2dp" Android: color = "# dcdcdc"/> <corners Android: radius = "2dp"/> <padding Android: Left = "10dp" Android: Top = "10dp" Android: Right = "10dp" Android: bottom = "10dp"/> </shape> </item> <item Android: state_focused = "true"> <shape> <gradient Android: startcolor = "# ffc2b7" Android: endcolor = "# ffc2b7" Android: angle = "270"/> <stroke Android: width = "2dp" Android: color = "# dcdcdc"/> <corners Android: radius = "2dp"/> <padding Android: Left = "10dp" Android: Top = "10dp" Android: Right = "10dp" Android: bottom = "10dp"/> </shape> </item> <shape> <gradient Android: startcolor = "# ff9d77" Android: endcolor = "# ff9d77" Android: angle = "270"/> <stroke Android: width = "2dp" Android: color = "# fad3cf"/> <corners Android: radius = "2dp"/> <padding Android: Left = "10dp" Android: Top = "10dp" Android: Right = "10dp" Android: bottom = "10dp"/> </shape> </item> </selector>

note! It is suggested that the differences between the preceding items are mainly reflected in that when state_pressed is pressed or state_focused gets the focus, Dangdang determines the display type, while items without the state_xxx attribute can be considered as normal.

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.