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.