1. use an XML Resource file to define colors. this method is highly scalable and easy to modify and share. for example, you can create a color in the values directory. xml 1. use an XML Resource file to define colors. this method is highly scalable and easy to modify and share. for example, you can create a color in the values directory. xml
#ffb52121
Defines a color named mycolor. in other places, you can reference mycolor to obtain the color value, as shown in
TextView definition:
Android:textColor="@drawable/mycolor"
2. use an XML Resource file to define a style. define a shape. xml file in res/drawable.
Instance code:
Define buttons in the xml of your Activity (such as activity_main.xml)
Shape attributes:
Solid
Description: internal filling.
Property: android: color fill color
Size
Description: size.
Attribute:
Android: width android: height
Gradient
Description: gradient.
Attribute:
Android: startColor gradient start color android: endColor gradient end color android: centerColor gradient intermediate color android: angle gradient angle, angle = 0, gradient from left to right, then it turns counter-clockwise. When angle is 90, the gradient changes from top to bottom. Angle must be a multiple of 45 android: type gradient type: linear (linear), radial (radioactive, starting color as the center), sweep (scanning line gradient) android: userLevel: to use the LevelListDrawable object, set it to true. Set true to no gradient, and false to gradient android: grdientRadial gradient radius. this value takes effect only when the type is set to radial. android: relative location of the X-point coordinate of the centerX gradient center android: relative position of the Y coordinate of the centerY gradient Center
Stroke
Description: stroke.
Attribute:
Android: width stroke width android: color stroke color android: dashwidth stroke width when the style is dotted line, when the value is 0 is solid line, when the value is greater than 0 is dotted line android: interval between dashGap when the stroke is a dotted line
Corners
Description: rounded corner.
Attribute:
Android: radius four-angle radius value android: topLeftRadius upper left corner radius value android: topRightRadius upper right corner radius value android: bottomLeftRadius lower right corner radius value android: bottomRightRadius lower left corner radius value
Padding
Description: padding.
Attribute:
Android: left padding android: right padding android: top padding android: bottom padding:
The preceding section details how to use an XML Resource file to define colors and styles. For more information, see other related articles in the first PHP community!