32

I have defined two themes with different primary, primary dark, primary light and accent colors.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
</style>

<style name="AppTheme2" parent="AppTheme">
    <item name="colorPrimary">@color/primary_2</item>
    <item name="colorPrimaryDark">@color/primary_dark_2</item>
    <item name="colorAccent">@color/accent_2</item>
</style>

AppTheme is default for <application/> Then I set AppTheme2 in specific activities.

In a drawable file xml I'm using the same primary colors of AppTheme defined in colors.xml

The drawable is used in many activities from both themes, so when there is AppTheme2 I see the different colors. Is there a way to make the drawable use the colors of the current theme for the current activity?

user3290180
  • 4,260
  • 9
  • 42
  • 77

1 Answers1

77

You can use this attribute to get color from currently used theme:

android:color="?colorPrimary"

This is possible only for android 5.0 or higher.

e-shfiyut
  • 3,538
  • 2
  • 30
  • 31