Reputation: 2997
I have Listview. I want the color of the text that I have selected to change to white once i have selected it, and to stay white, however when i select another item in the listview I want the previously selected item's color to revert to the default black and the newly selected item to change to white.
My color_selector.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="@color/black" />
<item android:state_focused="true" android:state_pressed="true"
android:color="@color/white" />
<item android:state_focused="false" android:state_pressed="true"
android:color="@color/white" />
<item android:color="@color/black" />
</selector>
This only turns the textcolor to white on if i keep the item pressed.
Upvotes: 0
Views: 76
Reputation: 13458
Use state_activated for this, you're really only handling press events in your selector, which is a transient condition that becomes false as soon as the user removes their finger.
You may alternatively be looking for state_selected, review Explanation of state_activated, state_selected, state_pressed, state_focused for ListView for more information.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
.
.
.
<item android:state_activated="true" android:color="@color/white" />
<item android:state_selected="true" android:color="@color/white" />
<item android:color="@color/black" />
</selector>
Upvotes: 1