Note that there are some explanatory texts on larger screens.

plurals
  1. PODefining XML Parent Style of Gradient / Shape / Corners
    primarykey
    data
    text
    <p>How can I define an easily reusable base shape (or gradient, or corners) in XML?</p> <p>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?</p> <p>This is the base:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"&gt; &lt;gradient xmlns:android="http://schemas.android.com/apk/res/android" android:type="linear" android:angle="270" android:startColor="#e1ffffff" android:endColor="#e100ff00"&gt; &lt;stroke android:width="1dp" android:color="#ff000000" /&gt; &lt;corners android:radius="4dp" /&gt; &lt;/gradient&gt; &lt;/shape&gt; </code></pre> <p>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.</p> <p>I tried using both parent and styles, but neither of them use any of the properties. For example:</p> <pre><code>&lt;style name="base_gradient"&gt; &lt;item name="android:angle"&gt;270&lt;/item&gt; &lt;item name="android:type"&gt;linear&lt;/item&gt; &lt;item name="android:startColor"&gt;#e1ffffff&lt;/item&gt; &lt;item name="android:endColor"&gt;#e100ff00&lt;/item&gt; &lt;/style&gt; </code></pre> <p>And then the drawable looks like:</p> <pre><code>&lt;gradient style="@style/base_gradient" /&gt; </code></pre> <p>That didn't work. I tried similarly putting the above in its own XML file and then doing this for each drawable:</p> <pre><code>&lt;gradient parent="@drawable/base_gradient" /&gt; </code></pre> <p>That did not work either.</p> <p>Is there a way to do this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload