我希望设计一个自定义文本选择器,当用户点击TextView时可以改变文本颜色。但是出现了以下错误:
java.lang.RuntimeException:无法启动活动ComponentInfo{}:android.view.InflateException:二进制XML文件第55行:错误膨胀类
这是我的代码: drawable/text_selector.xml
java.lang.RuntimeException:无法启动活动ComponentInfo{}:android.view.InflateException:二进制XML文件第55行:错误膨胀类
这是我的代码: drawable/text_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"
android:state_focused="true"
android:drawable="@color/black" />
<item android:state_pressed="true"
android:drawable="@color/blue" />
<item android:state_focused="true"
android:drawable="@color/black" />
</selector>
layout/textview.xml
<TextView android:id = "@+id/last_page_button"
android:text="@string/last_page_button_string"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
android:textColor = "@drawable/text_selector"
android:layout_weight="1" />
values/color.xml
<resources>
<color name="white">#ffffffff</color>
<color name="black">#ff000000</color>
<color name="blue">#ffccddff</color>
android:state_selected
才能工作。正如 @Herry 所指定的,这是从 Android SDK 示例中获取的: