How do you programmatically fill rectangle defined in xml
<p>I have a simple Android project with a rectangle defined in xml, but I can't find a way to pro grammatically fill it with a solid colour.</p>

<p>The main.xml file has the following</p>

<pre><code>&lt;ImageView
    android:id="@+id/Smoke20"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignTop="@+id/editText2"
    android:layout_marginLeft="26dp"
    android:src="@drawable/zonebox" /&gt;
</code></pre>

<p>Where zonebox is defined in res/drawable/zonebox.xml as follows</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;size
    android:width="80sp"
    android:height="20sp" /&gt;

&lt;stroke
android:width="1dp"
android:color="#88888888" /&gt;

&lt;!--  solid
    android:color="#0A0" /&gt;    
--&gt;
&lt;/shape&gt;
</code></pre>

<p>In my code, I can for example change the colour of boundary of the rectangle with
something like</p>

<pre><code>int colourBox = getResources().getColor(R.color.fire2_fire_color);
View rectTest = findViewById(R.id.Smoke20);
rectTest.setBackgroundColor(colourBox);
</code></pre>

<p>but I can't replicate in code the "solid" attribute that is so easily done in the xml as shown commented out. I'm obviously going about this the wrong way, but after considerable research, I'm still in the dark.</p>

<p>I have looked at getting the xml resource as follows, but this doesn't offer a suitable method for filling the rectangle either.</p>

<pre><code>ShapeDrawable viewTest = (ShapeDrawable)getResources().getDrawable(R.id.Smoke20);
</code></pre>

<p>Thanks</p>
