The Android custom control style is in the XML under the Drawable folder, which is achieved by setting the control's Background property in the layout file.
First, the control common state: used in the XML file selector node, selector can be understood as a state switcher, different states to switch the different styles, various states with the item node representation, The following are some common states (note: The first item in StateList that matches the current state is used.) Therefore, if the first item does not have any state attributes, then it will be used every time, which is why the default value must always be at the end, the various states can be cross-used): 1, Android:state_pressedboolean. "True" indicates the use of a pressed state (for example, a button is pressed); "false" indicates a non-pressed state. 2, Android:state_focusedboolean. "True" indicates that the focus state is used (for example, using a rolling ball/d-pad focus button); "False" indicates the use of a non-focused state. 3, Android:state_selectedboolean. "True" indicates that the selected state is used (for example, tab-Open); "false" indicates a unchecked state. 4, Android:state_checkableboolean. "True" indicates that the status can be checked and "false" means that it is not available for tick status. (Useful only for components that can toggle tick-not tick.) ) 5, Android:state_checkedboolean. "True" indicates that the check status is used; "false" indicates a non-tick status. 6, Android:state_enabledboolean. "True" indicates that the available state is used (can receive touch/click events); "False" indicates an unavailable state to use. 7, Android:window_focusedboolean. "True" indicates that the application window has focus when used (the application is in the foreground); "false" means use when there is no focus (for example, Notification Bar drop or dialog box display). shape's properties: Each state (item) corresponds to an effect, shape is used to define the shape, and the following are some common properties of shape: 1, Solid: Solid is the meaning of the fill android:color specifies the color of the fill 2, gradient: Gradient Android:startcolor and ANDROID:ENDCOlor are the start and end colors respectively, and the android:angle is the gradient angle and must be an integer multiple of 45. When angle=0, the gradient color is left to right. Then turn counterclockwise, when angle=90 is from bottom to top. In addition, the default mode of the gradient is android:type= "linear", that is, linear gradient, you can specify the gradient to radial gradient, android:type= "radial", radial gradient needs to specify the radius android:gradientradius= "50", You can also specify the synthesis of both, scan the gradient android:type= "sweep" 3, Stroke: Stroke android:width= "2DP" stroke width, android:color stroke color. We can also set the stroke as a dashed line in the form of: android:dashwidth= "5DP" android:dashgap= "3DP" which Android:dashwidth means '-' the width of a horizontal line, Android:dashgap represents the distance between them. 4, Corners: Rounded angle Android:radius is the radian of the angle, the larger the value the more rounded. We can also set the four angles to different angles, the method is: android:toprightradius= "20DP" upper right corner android:bottomleftradius= "20DP" lower right corner android:topleftradius= "1DP" upper left corner android:bottomrightradius= "0DP" lower left corner here's a place to note, Bottomleftradius is the lower-right corner, not the lower-left corner 5, panding: The inner moment below is a butto n Complete definition: <?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:angle= "android:endcolor=" #F FFFFF "android:startcolor=" #ff8c00 "/> <stroke android:width=" 2DP "an Droid:color= "#dcdcdc"/> <corners android:radius= "2DP"/> &n Bsp <padding android:bottom= "10DP" android:left= "10DP" android:right= "10DP" android:top= " 10DP "/> </shape> </item> <item and Roid:state_focused= "true" > <shape> <gradient Android:angle = "android:endcolor=" #ffc2b7 "android:startcolor=" #ffc2b7 "/> <stro Ke android:width= "2dp" android:color= "#dcdcdc"/> <corners Android:radi us= "2DP"/> <padding android:bottom= "10DP" android:left= "10DP" android:right= "10DP" android:top= "10DP"/> </shape> </item> <item> <shape> <gradient android:angle= "android:endcolor=" #ff9d77 " Android:startcolor= "#ff9d77"/> <stroke android:width= "2DP" Android:col Or= "#fad3cf"/> <corners android:radius= "2DP"/> <padding android:bottom= "10DP" android:left= "10DP" android:right= "10DP" android:top= "10DP"/& gt; </shape> </item> </selector>
(GO) Android's custom control style in XML implementation under the Drawable folder