Selvarathinam Vinoch
Selvarathinam Vinoch

Reputation: 1100

TextView color is not changing on click

I'm using selector to change textview color when user touch it. But the color is permanently black and not changing when touch. Here is my code :

@color/red.xml

<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="#ffffff" />
<item android:state_focused="false" android:state_pressed="true" android:color="#ffffff" />
<item android:color="#000000" />

textview :

 <TextView
    android:id="@+id/delete"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="59dp"
    android:layout_y="449dp"
    android:text="Delete"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="@color/red"
    android:textSize="20dp" />

Solution : Use setOnClickListener() for textview instead of setOnTouchListener().

Upvotes: 0

Views: 411

Answers (3)

Hardik
Hardik

Reputation: 17441

EDIT

<item android:drawable="@drawable/color_white" android:state_pressed="true"></item>
<item android:drawable="@drawable/color_black"></item>

in color.xml

<drawable name="color_black">#000000</drawable>
<drawable name="color_white">#ffffff</drawable>

Upvotes: 1

anddevmanu
anddevmanu

Reputation: 1459

Hi Please try this may be this is helpful

<item android:state_selected="true" android:color="#ffffff" />
<item android:state_focused="true" android:color="#000000" />
<item android:state_pressed="true" android:color="#000000" />
<item android:color="#000000" />

Upvotes: 0

Prashant Thakkar
Prashant Thakkar

Reputation: 1403

Try

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:color="#ffffff" />
<item android:state_pressed="true" android:color="#ff0000" />
<item android:color="#000000" />
</selector>

Upvotes: 0

Related Questions