【android】自定义控件属性设置

本文深入探讨了Android中各种属性格式与样式声明的应用场景,包括引用资源、颜色、布尔值、尺寸、浮点数、整型、字符串、百分数、枚举与位或运算等。通过实例展示了如何在XML布局文件中灵活使用这些特性来定制UI元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. reference:参考某一资源ID。


<declare-styleable name = "名称">
<attr name = "background" format = "reference" />
<attr name = "src" format = "reference" />
</declare-styleable>

 

2. color:颜色值。

<declare-styleable name = "名称">
<attr name = "textColor" format = "color" />
</declare-styleable>

 

3. boolean:布尔值。

<declare-styleable name = "名称">
<attr name = "focusable" format = "boolean" />
</declare-styleable>

 

4. dimension:尺寸值。


<declare-styleable name = "名称">
<attr name = "layout_width" format = "dimension" />
</declare-styleable>

 

5. float:浮点值。


<declare-styleable name = "名称">
<attr name = "fromAlpha" format = "float" />
<attr name = "toAlpha" format = "float" />
</declare-styleable>

 

6. integer:整型值。


<declare-styleable name = "名称">
<attr name = "frameDuration" format="integer" />
<attr name = "framesCount" format="integer" />
</declare-styleable>

 

7. string:字符串。


<declare-styleable name = "名称">
<attr name = "text" format = "string" />
</declare-styleable>

 

8. fraction:百分数。

<declare-styleable name="名称">
<attr name = "pivotX" format = "fraction" />
<attr name = "pivotY" format = "fraction" />
</declare-styleable>

 

9. enum:枚举值。


<declare-styleable name="名称">
<attr name="orientation">
<enum name="horizontal" value="0" />
<enum name="vertical" value="1" />
</attr>
</declare-styleable>

 

10. flag:位或运算。


<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.多类型


<declare-styleable name = "名称">
<attr name = "background" format = "reference|color" />
</declare-styleable>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值