title: 设置背景比较器失败
date: 2016-11-09 10:33:27
tags: problems
- 错误:
<item> tag requires a 'drawable' attribute or child tag defining a drawable
设置背景选择器的时候像常用的那样
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/leftmenu_pressed" />
<item android:color="@color/leftmenu_bg" />
</selector>
就会报错,目前只有在设置背景的时候碰到过。
- 解决办法
好吧,提示说我少drawable的话。。那么在colors.xml里面把<color>
标签替换成<drawable>
标签
<drawable name="leftmenu_pressed">#0f0f0f</drawable>
<drawable name="leftmenu_bg">#141414</drawable>
然后将选择器改成
<?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/leftmenu_pressed" />
<item android:drawable="@drawable/leftmenu_bg" />
</selector>
就好了.