If you're not satisfied with the UI controls that come with your Android system, you can try a custom control, and we'll take the button as an example, a long time ago Android123 wrote the Android button button control beautification method that mentions the selector constructs of XML. Of course, in addition to using images like Drawable, the Android web today talks about customizing the shape shapes, and supports the following properties on the button control Android shape, gradient, stroke, corners, and so on.
Let's take the current system button selector as an example:
<shape>
<gradient
android:startcolor= "#ff8c00"
android:endcolor= "#FFFFFF"
android: angle= "270"/>
<stroke
android:width= "2DP"
android:color= "#dcdcdc"/>
android:radius= "2DP"/>
<padding
android:left= "10DP"
android:top= "10DP"
Android : right= "10DP"
android:bottom= "10DP"/>
</shape>
For the above, the definition of this shape, respectively, is a gradient, in gradient the StartColor property is the beginning of the color, endcolor for the gradient end of the color, the following angle is the angle. Next is stroke can be understood as the edge, corners for the corner here Radius property is radius, and finally relative position attribute padding.
For a button The complete definition can be thought
<?xml version= "1.0" encoding= "Utf-8"?> <selector xmlns:android= "http://schemas.android.com/apk/res/" Android "> <item android:state_pressed=" true "> <shape> <gradient android:startcolor=" #ff8c00 "an
Droid: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> & Lt;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> <item> <shape> <gradient andRoid:startcolor= "#ff9d77" android:endcolor= "#ff9d77" android:angle= "270"/> <stroke android:width= "2DP" an Droid:color= "#fad3cf"/> <corners android:radius= "2DP"/> <padding android:left= "10DP" android:top= " 10DP "android:right=" 10DP "android:bottom=" 10DP "/> </shape> </item> </selector>
Note that Android123 tips, the difference between the above several item is mainly reflected in state_pressed press or state_focused gain focus, when to determine what type of display, and there is no state_xxx attributes of the item can be seen as normal state.
The above is to beautify the shape of the Android control data collation, the need for students to refer to.