For more information, see
<Shape>
<! -- Solid -->
<Solid Android: color = "# ff9d77"/>
<! -- Gradient -->
<Gradient
Android: startcolor = "# ff8c00"
Android: endcolor = "# ffffff"
Android: angle = "270" type = "parmname" text = "parmname"/>
<! -- Stroke -->
<Stroke
Android: width = "2dp"
Android: color = "# dcdcdc"/>
<! -- Rounded corner -->
<Corners
Android: radius = "2dp"/>
<Padding
Android: Left = "10dp"
Android: Top = "10dp"
Android: Right = "10dp"
Android: Bottom = "10dp"/>
</Shape>
Solid: solid, indicating Filling
Android: Color specifies the fill color
Gradient: Gradient
Android: startcolor and Android: endcolor are the start and end colors respectively. Android: angle is the gradient angle, which must be an integer multiple of 45.
In addition, the default gradient mode is Android: TYPE = "linear", that is, linear gradient. You can specify the gradient as a radial gradient, Android: TYPE = "RADIAL", and the radius must be specified for the radial gradient Android: gradientradius = "50 ".
Android: angle there are various sayings on the Internet. Here, I will talk about my experiment results, the most primitive in the gradient, that is, when Android: angle = "0, it is rendered from left to right based on the start color to the end color. Android: angle = "90" is rendered from top to bottom. Android: angle = "180" is rendered from right to left. Android: angle = "360" is the same as Android: angle = "0", so this should be the case here, when rendering, rotate the corresponding degree around the control center according to the original color palette (inside the control as a board that can rotate around the center), that is, Android: the value in angle is the desired rotation angle, but the rotation angle must be an integer multiple of 45.
Stroke: Stroke
Android: width = "2dp" stroke width, Android: Color stroke color.
We can also draw the stroke into a dotted line. The setting method is as follows:
Android: dashwidth = "5dp"
Android: dashgap = "3dp"
Android: dashwidth indicates the width of a horizontal line like '-', and Android: dashgap indicates the distance between them.
Corners: rounded corner
Android: radius is the Radian of an angle. The larger the value is, the closer the angle is.
We can also set the four angles to different angles:
<Corners
Android: toprightradius = "20dp" upper right corner
Android: bottomleftradius = "20dp" bottom right corner
Android: topleftradius = "1dp" upper left corner
Android: bottomrightradius = "0dp" lower left corner
/>
Note that bottomleftradius is in the lower right corner, rather than in the lower left corner. Remember this.
Some people on the Internet said that setting 0dp is invalid, but I found it works during the test. I used 2.2. Maybe this problem has been fixed, if it is invalid, it can only be set to 1dp.
Padding: interval
The interval between the text in the middle and the border.
In general, the following is a specific example: Used as the background of the button in selector, which defines the general status of the button, the obtained focus status, and the status when the button is pressed, respectively, the Code is as follows:
Main. xml:
<Button
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "testshapebutton"
Android: Background = "@ drawable/button_selector"
/>
Button_selector.xml:
<? XML version = "1.0" encoding = "UTF-8"?>
<Selector
Xmlns: Android = "http://schemas.android.com/apk/res/android">
<Item Android: state_pressed = "true">
<Shape>
<! -- Gradient -->
<Gradient
Android: startcolor = "# ff8c00"
Android: endcolor = "# ffffff"
Android: TYPE = "RADIAL"
Android: gradientradius = "50"/>
<! -- Stroke -->
<Stroke
Android: width = "2dp"
Android: color = "# dcdcdc"
Android: dashwidth = "5dp"
Android: dashgap = "3dp"/>
<! -- Rounded corner -->
<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" 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>
</Item>
<Item>
<Shape>
<Solid Android: color = "# ff9d77"/>
<Stroke
Android: width = "2dp"
Android: color = "# fad3cf"/>
<Corners
Android: toprightradius = "5dp"
Android: bottomleftradius = "5dp"
Android: topleftradius = "0dp"
Android: bottomrightradius = "0dp"
/>
<Padding
Android: Left = "10dp"
Android: Top = "10dp"
Android: Right = "10dp"
Android: Bottom = "10dp"/>
</Shape>
</Item>
</Selector>
The running effect is as follows:
General status:
Get focus status:
Press status: