android RadioButton注意事项

用RadioButton做个小控件,用selector作了个背景,selector里item的声明竟然要有顺序,好恶心。所以以后遇到定义的selector不管用 得注意下

<?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/btn_left_selected"/>
	<item android:state_pressed="true"
	 	android:drawable="@drawable/btn_left_selected"/>
	<item android:drawable="@drawable/btn_left"/>
</selector>

如果第三个item你放到第一个位置的话 你选择某个RadioButton,他的背景色不会变,我这里没有一一去试,遇到情况再说


还有如果不要默认的小圆圈背景,在RadioButton控件里加个属性 android:button="@null",使其背景属性为透明


此外,RadioButton的checked属性设置为true,代码里调用RadioButton的check(id)方法,不会触发onCheckedChanged事件


至于为什么 我在api文档里找到解释 

the selection is not based on the "best match," but simply the first item that meets the minimum criteria of the state.


http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList


Note: Remember that Android applies the first item in the state list that matches the current state of the object. So, if the first item in the list contains none of the state attributes above, then it is applied every time, which is why your default value should always be last (as demonstrated in the following example).


博客已搬到 http://marspring.mobi/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值