2

I try to change the color based on my theme. My TextView is using color-selector with different states for enabled and disabled and I want to use my theme based color in this selector.

I have followed this solution: android themes - defining colours in custom themes

My selector used as android:textColor in my view looks like this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="true" android:color="#ffffff" />
    <item android:state_enabled="false" android:color="?attr/ThemeTest"/>
</selector>

with ThemeTest being my custom attribut which has a color assigned in my themes. If I use this selector as my textColor, the color is actually not what I picked but just a simple plain RED! HOWEVER if I use the custom attribut directly in my view

android:textColor="?ThemeTest"

then it works but I obviously want to do this based on the change of state of my view...

Does anybody understand this behaviour and know how to fix it? Thanks in advance!

Community
  • 1
  • 1
ftb
  • 69
  • 10

1 Answers1

1

Using a theme attribute inside a color selector XML file is only supported in the most recent versions of Android. To overcome this limitation you need to create one color selector file for each theme, and fill them with plain colors. Then create a theme attribute which points to the correct color selector depending on the theme.

source: https://plus.google.com/102404231349657584821/posts/XEeehfwanGy

edit: tested and it works flawlessly!

ftb
  • 69
  • 10