How can I define an easily reusable base shape (or gradient, or corners) in XML?
I have a dozen or so drawable gradients that will be the same other than the start and end colors. I was hoping to define the identical stuff somewhere else and have an XML file for each different gradient that only defined the start and end colors. Is that possible?
This is the base:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient xmlns:android="http://schemas.android.com/apk/res/android"
android:type="linear"
android:angle="270"
android:startColor="#e1ffffff"
android:endColor="#e100ff00">
<stroke android:width="1dp"
android:color="#ff000000" />
<corners android:radius="4dp" />
</gradient>
</shape>
Then I wanted to overwrite the startColor and endColor (and maybe the corners radius too or any other property) in each drawable's XML file.
I tried using both parent and styles, but neither of them use any of the properties. For example:
<style name="base_gradient">
<item name="android:angle">270</item>
<item name="android:type">linear</item>
<item name="android:startColor">#e1ffffff</item>
<item name="android:endColor">#e100ff00</item>
</style>
And then the drawable looks like:
<gradient style="@style/base_gradient" />
That didn't work. I tried similarly putting the above in its own XML file and then doing this for each drawable:
<gradient parent="@drawable/base_gradient" />
That did not work either.
Is there a way to do this?