一、控件自定义属性介绍
以下示例中代码均在values/attrs.xml 中定义,属性均可随意命名。 1. reference:参考某一资源ID。 示例: [java] 代码如下: <declare-styleable name = "名称"> <attr name = "background" format = "reference" /> <attr name = "src" format = "reference" /> </declare-styleable> 2. color:颜色值。 示例: [java] 代码如下: <declare-styleable name = "名称"> <attr name = "textColor" format = "color" /> </declare-styleable> 3. boolean:布尔值。 示例: [java] 代码如下: <declare-styleable name = "名称"> <attr name = "focusable" format = "boolean" /> </declare-styleable> 4. dimension:尺寸值。 示例: [java] 代码如下: <declare-styleable name = "名称"> <attr name = "layout_width" format = "dimension" /> </declare-styleable> 5. float:浮点值。 示例: [java] 代码如下: <declare-styleable name = "名称"> <attr name = "fromAlpha" format = "float" /> <attr name = "toAlpha" format = "float" /> </declare-styleable> 6. integer:整型值。 示例: [java] 代码如下: <declare-styleable name = "名称"> <attr name = "frameDuration" format="integer" /> <attr name = "framesCount" format="integer" /> </declare-styleable> 7. string:字符串。 示例: [java] 代码如下: <declare-styleable name = "名称"> <attr name = "text" format = "string" /> </declare-styleable> 8. fraction:百分数。 示例: [java] 代码如下: <declare-styleable name="名称"> <attr name = "pivotX" format = "fraction" /> <attr name = "pivotY" format = "fraction" /> </declare-styleable> 9. enum:枚举值。 示例: [java] 代码如下: <declare-styleable name="名称"> <attr name="orientation"> <enum name="horizontal" value="0" /> <enum name="vertical" value="1" /> </attr> </declare-styleable> 10. flag:位或运算。 示例: [java] 代码如下: <declare-styleable name="名称"> <attr name="windowSoftInputMode"> <flag name = "stateUnspecified" value = "0" /> <flag name = "stateUnchanged" value = "1" /> <flag name = "stateHidden" value = "2" /> <flag name = "stateAlwaysHidden" value = "3" /> </attr> </declare-styleable> 11.多类型。 示例: [java] 代码如下: <declare-styleable name = "名称"> <attr name = "background" format = "reference|color" /> </declare-styleable>