Note that there are some explanatory texts on larger screens.

plurals
  1. POMultipe shapes inside shapes.xml in android
    primarykey
    data
    text
    <p>I have been searching for possibilities to define different shapes inside a single shapes.xml and refer to each one on some specific events.</p> <p>At last I've found a solution to my question. And the answer is using level-list. </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;level-list xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:maxLevel="0"&gt; &lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"&gt;    &lt;gradient android:startColor="#aaa" android:endColor="#eee" android:angle="270" /&gt;     &lt;corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" android:topLeftRadius="7dp" android:topRightRadius="7dp" /&gt; &lt;/shape&gt; &lt;/item&gt; &lt;item android:maxLevel="1"&gt; &lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"&gt;    &lt;gradient android:startColor="#eee" android:centerColor="#ddd" android:endColor="#00fff2" android:angle="270" /&gt;     &lt;corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" android:topLeftRadius="7dp" android:topRightRadius="7dp" /&gt; &lt;/shape&gt; &lt;/item&gt; &lt;/level-list&gt; </code></pre> <p>Apply this to the background attribute in the style. the Interchanging of differents shapes can be achieved by setting the level to that element.</p> <p>Eg: <code>findViewById(R.id.mybutton).getBackground().setLevel(1);</code></p> <p>In the above code I'm setting the second shape to the button with id mybutton.</p>
    singulars
    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.
 

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