首页 > 代码库 > 每日总结 - android设置背景颜色报错

每日总结 - android设置背景颜色报错

每天坚持总结,总会发生质变!

今天给radiobutton设置背景颜色报错,信息如下:

item> tag requires a ‘drawable‘ attribute or child tag defining a drawable

解决方法:

  你不能将颜色选择器用在background上,应该使用drawable selector。

 1 <selector xmlns:android="http://schemas.android.com/apk/res/android"> 2     <item android:state_checked="true"> 3         <shape> 4             <solid android:color="@color/orange"></solid> 5         </shape> 6     </item> 7     <item android:state_checked="false"> 8         <shape> 9             <solid android:color="@color/gray"></solid>10         </shape>11     </item>12 </selector>

 

每日总结 - android设置背景颜色报错