title: How to programmatically create or alter a drawable made of lines of different colors
body: <p>I have to draw a 3dp line to represent a level completion in a quizz game.</p>
  
  <p>This line must be of 2 colors. For example, if user has completed 40% of the level, the line will be red for the first 40% of the line, the other 60% being grey.</p>
  
  <p>I have managed to do that with a drawable :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item&gt;
          &lt;shape android:shape="line" &gt;
              &lt;size android:height="3dp" android:width="40dp"/&gt;
              &lt;stroke
                  android:width="1dp"
                  android:color="#FFFC10" /&gt;
          &lt;/shape&gt;
      &lt;/item&gt;
      &lt;item android:left="40dp"&gt;
          &lt;shape android:shape="line" &gt;
              &lt;size android:height="3dp" android:width="60dp" /&gt;
              &lt;stroke
                  android:width="1dp"
                  android:color="#DDDDDD" /&gt;
          &lt;/shape&gt;
      &lt;/item&gt;
  &lt;/layer-list&gt;
  </code></pre>
  
  <p>And then I display it with an ImageView :</p>
  
  <pre><code>&lt;ImageView
                  android:id="@+id/row_completion_bar"
                  android:src="@drawable/completion_bar"
                  android:layout_width="100dp"
                  android:layout_height="3dp" /&gt;
  </code></pre>
  
  <p>... but now, I must of course be able to change this 40%/60% ration depending of the actuel user completion.</p>
  
  <p>First question: what is the best most efficient way to do it ? Change the drawable at runtime ? or create a new drawable at runtime in Java ?</p>
  
  <p>Second question: how to do it ? I tried both ways (recreate this drawable in java code / alter the xml drawable at runtime) and didn't succeeded :-(</p>
  
  <p>Any help will be greatly appreciated.</p>