title: Drawing a Gradient Shape on Canvas
body: <p>It is easy to draw a rectangle with 1 basic color on a canvas. However, I need to be able to draw a shape with a gradient that starts with one color and evenly shifts to another. </p>
  
  <p>I'm used to drawing backgrounds with gradients by using xml files. Is there a way to reference an xml file when drawing a shape to the canvas? Or is there a better way to draw a gradient shape? </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;layer-list&gt;
              &lt;item&gt;
                  &lt;shape&gt;
                       &lt;!--  Gradient Bg for Button --&gt;
                       &lt;gradient
                            android:startColor="@color/button_type1_pushed"
                            android:endColor="@color/button_type1_pushed"
                            android:angle="270" /&gt;
                       &lt;stroke
                            android:width="0.05dp"
                            android:color="@color/button_type1_border"/&gt;
                  &lt;/shape&gt;
              &lt;/item&gt;
          &lt;/layer-list&gt;
      &lt;/item&gt;
  
      &lt;item android:state_enabled="true"&gt;
          &lt;layer-list&gt;
              &lt;item&gt;
                  &lt;shape android:shape="rectangle"&gt;
                      &lt;gradient
                           android:startColor="@color/button_type1_normal"
                           android:endColor="@color/button_type1_normal"
                           android:angle="90" /&gt;
                      &lt;stroke
                           android:width="0.05dp"
                           android:color="@color/button_type1_border"/&gt;    
                  &lt;/shape&gt;
              &lt;/item&gt;
          &lt;/layer-list&gt;
      &lt;/item&gt;
  &lt;/selector&gt;
  </code></pre>