AVEbrahimi
AVEbrahimi

Reputation: 19214

make Colors.xml dynamic by referecing to theme

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"/>

Upvotes: 0

Views: 114

Answers (1)

Rod_Algonquin
Rod_Algonquin

Reputation: 26198

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>

Upvotes: 1

Related Questions