【发布时间】:2011-03-31 04:43:55
【问题描述】:
我按照this tutorial 为特定的 Android 视图创建了颜色状态列表。我只是希望它在单击时突出显示,以便用户知道为什么屏幕刚刚改变。
当视图被渲染时,我得到以下错误:
org.xmlpull.v1.XmlPullParserException:二进制 XML 文件第 3 行:标签需要“drawable”属性或定义可绘制对象的子标签
我的颜色 XML(在 res/color/viewcolor.xml 中):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#ff33ffff"/> <!-- pressed -->
<item android:color="#ff000000"/> <!-- default -->
</selector>
我的布局 XML(在 res/layout/myview.xml 中):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myview"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:background="@color/viewcolor">
<!--crap in the layout-->
</LinearLayout>
我错过了什么?
【问题讨论】:
-
如果有人想获得完整的解决方案,请检查此存储库:github.com/shamanland/AndroidLayoutSelector 有自定义可点击/可检查
LinearLayout就像ToggleButton