one: In Android development , we often use shape to define a variety of shapes, and first we know what labels are underneath shape, and what they mean:
(1). Solid: Filling
Android:color Specify the color of the fill
(2). Gradient: Gradient
Android:startcolor and Android:endcolor, respectively, are the starting and ending colors,
Android:angle is a gradient angle and must be an integer multiple of 45.
In addition, the default mode of the gradient is android:type= "linear", which is a linear gradient,
You can specify a gradient to be a radial gradient, android:type= "radial", and a radial gradient that requires a radius of android:gradientradius= "50".
The angle value corresponds to the position shown below:
(3). Stroke: Strokes
Android:width= the width of the "2DP" stroke, android:color the stroke color.
We can also make the stroke in the form of a dotted line, set in the following way:
Android:dashwidth= "5DP"
android:dashgap= "3DP"
Where android:dashwidth means '-' the width of such a horizontal line, android:dashgap the distance between
(4). Corners: Rounded Corners
Android:radius is the angle of the radian, the greater the value of the more rounded corners.
We can also set the four corners to different angles and set five properties, the Radius property is invalid
android:radius= "20DP" sets the radius of Four Corners
android:topleftradius= "20DP" sets the radius of the upper-left corner
android:toprightradius= "20DP" sets the radius of the upper right corner
android:bottomleftradius= "20DP" sets the radius of the lower right corner
android:bottomrightradius= "20DP" sets the radius of the lower-left corner
(5). padding: Interval
You can set an interval of four directions up or down
Two: The code is as follows:
(1). Button_bg.xml as follows:
<?xml version= "1.0" encoding= "Utf-8"?> <shape xmlns:android=
"http://schemas.android.com/apk/res/" Android ">
<!--gradient-->
<gradient
android:endcolor=" #FFFFFF "
android:gradientradius=" "
android:startcolor=" #ff8c00 "android:type=" radial "
/>
<!--stroke-->
<stroke
android:dashgap= "3DP"
android:dashwidth= "5DP"
android:width= "2DP"
android:color= "#dcdcdc"/>
<!--fillet-->
<corners android:radius= "5DP"/>
<!--interval-->
<padding
Android:bottom= "10DP"
android:left= "10DP"
android:right= "10DP"
android:top= "10DP"/>
</shape>
(2). Shape_image.xml as follows:
<?xml version= "1.0" encoding= "Utf-8"?> <shape xmlns:android=
"http://schemas.android.com/apk/res/" Android >
<!--fill-->
<solid android:color= "#ff9d77"/>
<!--define the color value of the fill-->
--Stroke-->
<stroke
android:width= "2DP"
android:color= "#fad3cf"/>
<!--defines the color value of the stroke's width and stroke- >
<!--rounded corner-->
<corners
android:bottomleftradius= "5DP"
android:bottomrightradius= "5DP"
android:topleftradius= "5DP"
android:toprightradius= "5DP"/>
<!--set a radius of Four Corners-->
<!--interval-->
<padding
android:bottom= "10DP"
android:left= "10DP"
android:right= "10DP"
android:top= "10DP"/>
<!--set the interval of each direction-->
</shape>
(3). Button.xml as follows:
<?xml version= "1.0" encoding= "Utf-8"?> <selector xmlns:android=
"http://schemas.android.com/apk/res/" Android >
<item android:drawable= "@drawable/button_pressed_bg" android:state_pressed= "true" ></ item>
<item android:drawable= "@drawable/shape_image" ></item>
</selector>