Android背景选择器selector 中enable选项失效

来源:互联网 发布:中国进口数据分析 编辑:程序博客网 时间:2024/06/05 08:03

今天在使用TextView 设置背景颜色时发现没法TextView的颜色不能设置enable = false;

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_pressed="true" android:drawable="@drawable/tv_visit_bg_press"/>    <item android:drawable="@drawable/tv_visit_bg_normal"/>     <item android:state_enabled="false" android:drawable="@drawable/tv_disable"/></selector>

然后google了一下,发现代码中颜色匹配是顺序原则,只要找到第一个符合要求的,就不再继续往下执行了。所以只要把enable提前改成下面的顺序就可以正常展示了。

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_enabled="false" android:drawable="@drawable/tv_disable"/>    <item android:state_pressed="true" android:drawable="@drawable/tv_visit_bg_press"/>    <item android:drawable="@drawable/tv_visit_bg_normal"/></selector>
1 0
原创粉丝点击