Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>i was going through all related topics but no one could solve my problem. But some of them were very useful to understand how the layer-list or shape parameters work. </p> <p>My problem was to define a button with a linear gradient and draw a top and a bottom line in different colors. After all I hacked this solution. I saved the file unter res/drawable/blue_btn.xml</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;item android:state_pressed="true" &gt; &lt;shape android:shape="rectangle"&gt; &lt;solid android:color="@color/blue_end" /&gt; &lt;padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /&gt; &lt;stroke android:width="1dp" android:color="@color/bottomline_btn" /&gt; &lt;/shape&gt; &lt;/item&gt; &lt;item&gt; &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;item&gt; &lt;shape android:shape="rectangle"&gt; &lt;solid android:color="@color/blue" /&gt; &lt;gradient android:startColor="@color/blue" android:endColor="@color/blue_end" android:angle="270" /&gt; &lt;/shape&gt; &lt;/item&gt; &lt;item android:top="0dp" android:bottom="-1dp" android:left="-1dp" android:right="-1dp"&gt; &lt;shape android:shape="rectangle"&gt; &lt;stroke android:width="1dp" android:color="@color/topline_btn" /&gt; &lt;solid android:color="#00000000" /&gt; &lt;corners android:radius="0dp" /&gt; &lt;/shape&gt; &lt;/item&gt; &lt;item android:top="-1dp" android:bottom="0dp" android:left="-1dp" android:right="-1dp"&gt; &lt;shape android:shape="rectangle"&gt; &lt;stroke android:width="1dp" android:color="@color/bottomline_btn" /&gt; &lt;solid android:color="#00000000" /&gt; &lt;corners android:radius="0dp" /&gt; &lt;/shape&gt; &lt;/item&gt; &lt;/layer-list&gt; &lt;/item&gt; &lt;/selector&gt; &lt;color name="topline_btn"&gt;#31ffffff&lt;/color&gt; &lt;color name="bottomline_btn"&gt;#31000000&lt;/color&gt; &lt;color name="blue"&gt;#449def&lt;/color&gt; &lt;color name="blue_end"&gt;#2f6699&lt;/color&gt; </code></pre>
 

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