0

How can I have colros defined in Colors.xml as dynamic?

My static colors.xml is like

<?xml version="1.0" encoding="utf-8"?> <resources> <color name="background">#ffffff</color> <color name="foreground">#000000</color> </resources> 

By I need something like this which refers to colors defined in themes.xml. The way I defined colors in below doesn't work

<?xml version="1.0" encoding="utf-8"?> <resources> <color name="background">?theme_color_background</color> <color name="foreground">?theme_color_foreground</color> </resources> 

I need this way to keep an old big project intact and just change theme. I referenced colors.xml like this in old project in a way like this:

<TextView textColor="@colors/foreground"/> 
4
  • why not just call it directly from the textColor instead of wrapping it in color.xml Commented Aug 30, 2014 at 7:30
  • As i said its for old project and referenced colors.xml hundreds of time in different layouts Commented Aug 30, 2014 at 7:32
  • post your them_color Commented Aug 30, 2014 at 7:38
  • You could what@ @Rod_Algonquin suggested and then do a global replace on textColor="@colors/foreground" Commented Aug 30, 2014 at 7:45

1 Answer 1

1

You can not reference a color from your theme but you can reference a color from the android default color.xml to wrap it in your color.xml

sample:

<color name="black">@android:color/background_dark</color> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.