0

I have a navigation drawer and a text selector which works really well. But I have a Dark theme where this selector have to be another, So I switch the selector at the ListAdapter like this

textView.setTextColor(rowView.getResources().getColor(R.color.textselector_dark));`

But now if I choose the dark theme the pressed color doesn't show just the default My text selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:state_activated="true"
    android:color="@color/pressed_text_color"/>
<item
    android:color="@color/default_color" />

Grimxn
  • 22,115
  • 10
  • 72
  • 85
Csabi Vidó
  • 146
  • 1
  • 12
  • Is your pressed color is same as theme color ? If not then your Dark theme is overridding android:color="@color/pressed_text_color" this property of all textviews. – Ganesh AB Dec 10 '14 at 13:38
  • this is how my themes.xml look like – Csabi Vidó Dec 10 '14 at 13:42

1 Answers1

0

You have to use setTextColor(ColorStateList).The normal setTextColor(int) sets the color for all states, as its JavaDoc clearly states:

Sets the text color for all the states (normal, selected, focused) to be this color.

Ridcully
  • 23,362
  • 7
  • 71
  • 86
  • ***setTextColor(ColorStateList)*** method does same thing which ***selector.xml*** does. Are you sure about this pro-grammatical implementation ? – Ganesh AB Dec 10 '14 at 13:47
  • thanks I have to use this:textView.setTextColor(rowView.getResources().getColorStateList(R.color.textselector_dark)); – Csabi Vidó Dec 10 '14 at 13:51
  • Yeah its working what i wrote. I had to use getResources().getColorState instead of getColor and it works – Csabi Vidó Dec 10 '14 at 14:00