Reputation: 51
I'm using this code sheet to define textView's color in different events. The textView is in listView (10+ items) and the effect (color) applies on every textView in every listItem. How I can change color of only textView that is pressed?
<?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="true"
android:color="@color/text_white" />
<item
android:state_focused="false"
android:state_pressed="true"
android:color="@color/text_white" />
<item
android:state_focused="true"
android:color="@color/text_white" />
<item
android:state_selected="true"
android:color="@color/text_white" />
<item
android:state_checked="true"
android:color="@color/text_white" />
<item
android:state_selected="false"
android:state_checked="false"
android:state_focused="false"
android:state_pressed="false"
android:color="@color/text_blue" />
</selector>
Upvotes: 0
Views: 1519
Reputation: 40416
try this
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" //<<<<<Here focus us true then txt_pressed
android:state_pressed="false"
android:drawable="@drawable/txt_pressed" />
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/txt_pressed" />
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/txt_pressed" />
<item android:drawable="@drawable/txt_default" />
</selector>
Upvotes: 1
Reputation: 673
In the xml file, to the textview you want to change color, add
android:background="@drawable/filename"
Upvotes: 0