title: 設(shè)置背景比較器失敗
date: 2016-11-09 10:33:27
tags: problems
- 錯(cuò)誤:
<item> tag requires a 'drawable' attribute or child tag defining a drawable
設(shè)置背景選擇器的時(shí)候像常用的那樣
<?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>
就會(huì)報(bào)錯(cuò),目前只有在設(shè)置背景的時(shí)候碰到過。
- 解決辦法
好吧,提示說我少drawable的話。。那么在colors.xml里面把<color>標(biāo)簽替換成<drawable>標(biāo)簽
<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>
就好了.