<shape> <!--solid--> <solid android:color= "#ff9d77"/ > <!--gradient--> <gradient & nbsp; android:startcolor= "#ff8c00" android:endcolor= "#FFFFFF" android:angle= "/> <!" --Stroke--> <stroke android:width= "2DP " android:color=" #dcdcdc "/> <!--rounded corners --> <corners android:radius= "2DP"/ > <padding android:left= "10DP" android:top= "10DP" android:right= "10DP" Android:bottom= "10DP"/> </shape>
Solid: Filled meaning android:color Specifies the color of the fill
Gradient: The gradient android:startcolor and Android:endcolor are start and end colors respectively, Ndroid:angle is the gradient angle and must be an integer multiple of 45. 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".
Stroke: The width of the stroke android:width= "2DP" stroke, android:color the color of the stroke. We can also make the stroke into a dashed line, set in the form: android:dashwidth= "5DP"
android:dashgap= "3DP" where android:dashwidth represents '-' the width of a horizontal line, Android:dashgap represents the distance between them.
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 by:
<corners android:toprightradius= "20DP" upper right corner android:bottomleftradius= "20DP" lower right corner Andro id:topleftradius= "1DP" upper left corner android:bottomrightradius= "0DP" lower left corner/>
Here is a place to pay attention, Bottomleftradius is the lower right corner, not the lower left corner, this is a bit depressed, but do not affect the use, remember not to make a mistake on the line. There are also online to see someone said set to 0DP invalid, but I found in the test is OK, I use 2.2, may fix the problem, if it is invalid, it can only be set to 1DP.
padding: Interval This is not much to say, XML layout files are often used.
In general, the following is a specific example of use: using the background as a button in selector, define the normal state of the buttons, the state of the focus and the state of the press, the code is as follows:
Main.xml: <button android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:text = "Testshapebutton" android:background= "@drawable/button_selector"/> >
Button_selector.xml:
<?xml version= "1.0" encoding= "Utf-8"?> <selector xmlns:android= "/http Schemas.android.com/apk/res/android "> <item android:state_pressed=" true "> <shape> <!--gradient--> < gradient Android:startcolor= "#ff8c00" android:endcolor= "#FFFFFF" android:type= "Radial" android:gradientradius= "/> " <!--strokes--> <stroke android:width= "2DP" android:color= "#dcdcdc" android:dashwidth= "5DP" android:dashgap= "3DP"/> <!--fillet--> <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> <gradient android:startcolor= "#ffc2b7" android:endcolor= "#ffc2b7" android:angle= "/> " <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> <solid android:color= "#ff9d77"/> <stroke android:width= "2DP" android:color= "#fad3cf"/> <corners android:toprightradius= "5DP" android:bottomleftradius= "5DP" android:topleftradius= "0DP" android:bottomrightradius= "0DP" /> <padding android:left= "10DP" android:top= "10DP" android:right= "10DP" android:bottom= "10DP"/> </shape> </item> </selector>
Android:drawable put a drawable resource android:state_pressed whether to press, such as a button touch or click. Whether the android:state_focused has the focus, such as when a user selects a text box. Android:state_hovered the cursor is hovering, usually the same as focused state, which is a new feature of 4.0 android:state_selected is selected, which is not exactly the same as the focus state, such as a list When the view is selected, the various sub-components within it may be selected through the arrow keys. Whether the Android:state_checkable component can be check. For example: RadioButton can be check. Android:state_checked was checked, such as: A RadioButton can be check. Android:state_enabled is able to accept touch or click event android:state_activated is activated (this trouble for example, not special understanding) android:state_window_focused Whether the application is in the foreground, when a notification bar is pulled down or a dialog box pops up, the application is not in the foreground. Note: If there are multiple item, then the program will automatically match from top to bottom, and the first match will be applied. (not through Best Bets) if an item does not have any status descriptions, it can be matched by any one of the states.
Using shape in Android selector