Binary XML file line #4: <item> tag requires a 'drawable' attribute or child tag defining a drawable

在LinearLayout中利用selector实现按钮点击效果的时候,发现错误如下:

Binary XML file line #4: <item> tag requires a 'drawable' attribute or child tag defining a drawable

LinearLayout使用代码

<LinearLayout
        android:id="@+id/ll_patient"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/selector_blue47_and_white"
        android:gravity="center"
        android:orientation="vertical" >

selector的错误代码

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/blue_47" android:state_selected="true"/>
<item android:color="@color/white" android:state_selected="false"/>
</selector>

selector的正确代码修改android:color为android:drawable即可

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/blue_47" android:state_selected="true"/>
<item android:drawable="@color/white" android:state_selected="false"/>
</selector>

估计LinearLayout中是background属性,所以是需要 用drawable 而不是 color

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念