如何在XML中定义容易重用的基础形状(或渐变或角点)?定义渐变/形状/角的XML父样式
我有一打左右的可绘制渐变,将是除开始和结束颜色以外。我希望能够在其他地方定义相同的东西,并为每个不同的渐变使用XML文件,这些渐变只定义了开始和结束的颜色。那可能吗?
这是基础:
<?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>
然后我想覆盖startColor和ENDCOLOR(也许弯道半径过或任何其他财产)在每个绘制的XML文件。
我试着使用父母和样式,但他们都没有使用任何属性。例如:
<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>
然后被拉伸的样子:
<gradient style="@style/base_gradient" />
这没有奏效。我试图把类似上述在自己的XML文件,然后执行此操作为每个绘制:
<gradient parent="@drawable/base_gradient" />
这也不能工作。
有没有办法做到这一点?