Android ApiDemos示例解析(105):Views->Buttons

Buttons 示例介绍了定义Button,ToggleButton的基本方法。本例在/res/layout/buttons_1.xml 定义如下:

<!– Regular sized buttons –>
<Button android:id=”@+id/button_normal”
android:text=”@string/buttons_1_normal”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />

<!– Small buttons –>
<Button android:id=”@+id/button_small”
style=”?android:attr/buttonStyleSmall”
android:text=”@string/buttons_1_small”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />

<ToggleButton android:id=”@+id/button_toggle”
android:text=”@string/buttons_1_toggle”
android:textOn=”Open”
android:textOff=”Close”

android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />

定义button 不指定任何风格时,Android以正常大小显示Button,

风格 ?android:attr/buttonStyleSmall 以紧凑风格显示Button。

在引用Style 属性值时, 使用“?” 而非”@” 来指定所需风格属性,格式如下:

?[<package_name>:][<resource_type>/]<resource_name>

其中resource_type部分可选,因此 本例也可以使用如下定义:

style=”?android:buttonStyleSmall”

ToggleButton 使用button 形式定义两种状态,比如Open,Close。缺省文本为ON, OFF, 可以使用属性textOn,textOff 重新定义文字。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值