1

I've been using theme attributes in all my drawables, but I found out that this is not supported pre-21

Is there a method I can use to use

<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="?attr/background_1" />
<corners android:radius="@dimen/button_corner_radius" />

And such drawables in my layouts? Thanks a lot. Not sure what to do now

K. B
  • 17
  • 4

1 Answers1

2

You can't do it from the xml file. As you can see in this answer, you have to create as many different resource files as background colours you want to use. In your case, if we call your file shape_drawable.xml:

in styles.xml

<attr name="shape_drawable" format="reference"/>

then in the actual themes:

// Theme X
<item name="shape_drawable">@drawable/shape_drawable_x</item>
// Theme Y
<item name="shape_drawable">@drawable/shape_drawable_y</item>

where shape_drawable_x would use solid color x and shape_drawable_y would use solid color y.

Then, in the place where you actually use the drawable:

android:src="?attr/shape_drawable"