我以前这样做过。我复制粘贴。我从网上复制粘贴了许多其他示例。我根本无法使 textcolor 选择器工作。它将默认颜色设置为 textview,但如果单击 textview,它不会改变。背景的 settings_selector 工作正常。
这是布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/settings_selector"
android:clickable="true"
android:id="@+id/llRecentChanges"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/llRecentChanges2"
android:layout_weight="1"
android:layout_gravity="center_vertical">
<TextView
android:id="@+id/tvAbout"
android:text="@string/settings_recentchanges"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
android:textColor="@drawable/settings_selector_txt" >
</TextView>
<TextView
android:id="@+id/tvAbout2"
android:text="@string/settings_recentchanges2"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@drawable/settings_selector_txt"
android:textSize="10dp">
</TextView>
</LinearLayout>
</LinearLayout>
这是 settings_selector_txt xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:state_pressed="false"
android:color="#FFFFFF" />
<item android:state_focused="true"
android:state_pressed="true"
android:color="#ffa800" />
<item android:state_focused="false"
android:state_pressed="true"
android:color="#ffa800" />
<item android:color="#FFFFFF" />
</selector>
或这个
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="#444"/>
<item android:state_focused="true" android:color="#444"/>
<item android:state_pressed="true" android:color="#444"/>
<item android:color="#ccc"/>
</selector>
或这个
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:color="#ffffff" />
<item android:state_focused="true" android:state_pressed="true" android:color="#000000" />
<item android:state_focused="false" android:state_pressed="true" android:color="#000000" />
<item android:color="#ffffff" />
</selector>
他们都没有工作。将选择器 xml 放入颜色文件夹也不是解决方案。有任何想法吗?