First, create an XML file named Gradient_box under the Res/drawable folder:
<?xml version= "1.0" encoding= "Utf-8"?>
<!--
A geometry defined in the shape drawable XML file, defined in the res/drawable/directory, with the file name filename filename called the resource ID of the access
Accessed through R.drawable.filename in code, accessed through @[package:]drawable/filename in an XML file.
-
<!--
android:shape=["Rectangle" | "Oval" | "Line" | "Ring"]
Shape, which is the default rectangle, can be set to rectangle (rectangle), oval (oval), linear shape (line), Loop (ring)
The following properties are available only at android:shape= "Ring:
Android:innerradius size, radius of inner ring.
Android:innerradiusratio floating-point type, which represents the radius of the inner ring at the width ratio of the ring.
For example, if Android:innerradiusratio indicates that the inner ring radius is equal to the width of the ring divided by 5, the value can be overwritten and the default is 9.
Android:thickness size, ring thickness
Android:thicknessratio float, which represents the thickness of the ring at the width ratio of the ring, for example, if android:thicknessratio= "2",
Then the thickness of the ring is equal to the width of the ring divided by 2. This value can be overridden by android:thickness, and the default value is 3.
The Android:uselevel Boolean value, or False if it is used as a levellistdrawable using the value of true.
-
<shape
Xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:shape= "Rectangle" >
<!--
Rounded Corners
Android:radius integer radius
Android:topleftradius integer upper-left corner radius
Android:toprightradius integer upper right corner radius
Android:bottomleftradius integer-left corner radius
Android:bottomrightradius integer Right bottom corner radius
-
<corners
Android:radius= "8DP"
Android:topleftradius= "5DP"
Android:toprightradius= "15DP"
Android:bottomleftradius= "20DP"
Android:bottomrightradius= "25DP"
/>
<!--
Fade color
Android:startcolor Color value Start color
Android:endcolor Color Value End Color
Android:centercolor integer gradient middle color, which is the color between the start and end colors
Android:angle integer Gradient angle (PS: When angle=0, the gradient is left-to-right. Then turn counterclockwise, when angle=90 is from bottom to top. Angle must be an integer multiple of 45)
Android:type ["Linear" | "Radial" | "Sweep"] Gradient type (value: Linear, radial, sweep)
Linear linear gradient, which is the default setting
Radial a radioactive gradient, centered on the starting color.
Sweep the gradient of the scanned line type.
Android:uselevel ["True" | FALSE] set to TRUE if you want to use the Levellistdrawable object. Set to True no gradient. False with gradient color
Android:gradientradius integral gradient radius. Used when android:type= "radial". Using android:type= "Radial" alone will cause an error.
Android:centerx the relative position of the X-point coordinates of the integer gradient center
Relative position of Y-point coordinates of Android:centery integral gradient Center
-
<gradient
Android:startcolor= "#FFFF0000"
Android:endcolor= "#80FF00FF"
Android:angle= "45"
/>
<!--
Padding, that is, the distance between the content and the edge
Android:left Integer left inner margin
Android:top integral type upper inner margin
Android:right Integral right inner margin
Android:bottom integral type lower inner margin
-
<padding
android:left= "10DP"
android:top= "10DP"
android:right= "10DP"
Android:bottom= "10DP"
/>
<!--
Size sizes
Android:width width of integral type
Android:height height of integral type
-
<size
Android:width= "600DP"
/>
<!--
Internal padding
Android:color Color value Fill Color
-
<solid
Android:color= "#ffff9d77"
/>
<!--
Strokes
Android:width the width of an integer stroke
Android:color Color Value Stroke color
The Android:dashwidth integer indicates that the style of the stroke is the width of the dashed line, and the value is 0 o'clock, which is expressed as solid. A value greater than 0 is a dashed line.
Android:dashgap integer indicates that a stroke is a dashed line, the interval between dashes is "----"
-
<stroke
Android:width= "2DP"
Android:color= "#dcdcdc"
/>
</shape>