0

I want to create a custom textview style where the text color changes on focus or on being selected and when released or not focused it changes back to the default color I have set. Below is my custom style I declared and applied to the style element of my textview

 <style name="CustomTextview" parent="android:style/Widget.Holo.TextView">
    <item name="android:state_pressed">@android:color/holo_red_dark</item>
    <item name="android:state_selected">@android:color/holo_red_dark</item>
    <item name="android:state_focused">@android:color/holo_red_dark</item>
</style>


 <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Yes"
        android:id="@+id/textView2"
        android:layout_weight="1"
        android:gravity="center"
        android:textStyle="bold"
        android:editable="false"
        android:singleLine="true"
        android:clickable="true"
        android:padding="10dp"
        style="@style/CustomTextview"
        android:focusable="true"/>

Currently nothing happens when I toch the textview, the default color is black and when I press the textview the color remains black.

kabuto178
  • 3,129
  • 3
  • 40
  • 61

2 Answers2

1

You should use a selector resource for this purpose.

cybersam
  • 63,203
  • 6
  • 53
  • 76
0

You should follow this tutorial http://developer.android.com/guide/topics/resources/color-list-resource.html

Then you need to sect text color of TextView with color that you have define

Liem Vo
  • 5,149
  • 2
  • 18
  • 16