用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
博客已搬到 http://marspring.mobi/