Android shape and selector, androidselector
1. shape usage example:
<Shape> <! -- Solid --> <solid android: color = "# ff9d77"/> <! -- Gradient --> <gradient android: startColor = "# ff8c00" android: endColor = "# FFFFFF" android: angle = "270"/> <! -- Stroke --> <stroke android: width = "2dp" android: color = "# dcdcdc"/> <! -- Rounded corner --> <corners android: radius = "2dp"/> <padding android: left = "10dp" android: top = "10dp" android: right = "10dp" android: bottom = "10dp"/> </shape>
- Solid: solid, indicating Filling
- Gradient: gradient
Android: startColor and android: endColor are the start and end colors respectively. android: angle is the gradient angle, which must be an integer multiple of 45.
In addition, the default gradient mode is android: type = "linear", that is, linear gradient. You can specify the gradient as a radial gradient, android: type = "radial", and the radius must be specified for the radial gradient android: gradientRadius = "50 ".
Android: width = "2dp" stroke width, android: color stroke color.
We can also draw the stroke into a dotted line. The setting method is as follows:
Android: dashWidth = "5dp"
Android: dashGap = "3dp"
Android: dashWidth indicates the width of a horizontal line like '-', and android: dashGap indicates the distance between them.
Android: radius is the Radian of an angle. The larger the value is, the closer the angle is.
2. Examples of selector usage:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@drawable/enabled_on_pressed" /> <item android:state_pressed="true" android:drawable="@drawable/enabled_on_pressed" /> <item android:drawable="@drawable/disabled_off" /> </selector>
Drawable items can have the following attributes:
Android: drawable = "@ [package:] drawable/drawable_resource"
Android: state_pressed = ["true" | "false"]
Android: state_focused = ["true" | "false"]
Android: state_selected = ["true" | "false"]
Android: state_active = ["true" | "false"]
Android: state_checkable = ["true" | "false"]
Android: state_checked = ["true" | "false"]
Android: state_enabled = ["true" | "false"]
Android: state_window_focused = ["true" | "false"]
The order of items is exquisite. the more detailed the conditions are, the more advanced the conditions should be.