问题
I have a custom ListView selector which draws on top of a ListView. It works fine, but I want the text inside of the listview to turn white. How can I do that?
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:state_focused="true"
android:drawable="@drawable/stocks_gradient" />
<item android:state_pressed="true"
android:drawable="@drawable/swipeview_selected_gradient" />
<item android:state_focused="true"
android:drawable="@drawable/swipeview_selected_gradient" />
</selector>
回答1:
You need to apply specific color or selector to each list item.
I have something like this (abreviated)
layout/dash_item.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/DashboardListItem">
... Your text components etc ....
color/dashboard_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:state_focused="true"
android:drawable="@android:color/transparent" />
<item android:state_pressed="true"
android:drawable="@color/dash_border_color" />
<item android:state_focused="true"
android:drawable="@color/dash_border_color" />
</selector>
values/style.xml
<style name="DashboardListItem">
<item name="android:background">@color/dashboard_selector</item>
</style>
You probably will need to play with it to figure where exactly apply things. It can probably be simplified. Anyway, it's just a direction since I don't know your specific requirements.
来源:https://stackoverflow.com/questions/6146333/how-to-create-a-state-list-drawable-for-my-listview-items