title: Changing gradient of XML
body: <p>I have a textview that gets the file called background.xml as its background.. This is the code for background.xml</p>
  
  <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  &lt;item android:state_enabled="true"&gt;
  &lt;shape android:padding="50dp"
  android:shape="rectangle"&gt;
  &lt;gradient android:startColor="@color/sendDarkColorGreen"   android:centerColor="@color/sendDarkColorGreen" android:endColor="@color/sendLightColorGreen" android:angle="90"/&gt;
  </code></pre>
  
  <p>
      
      
      
      </p>
  
  <p>I am trying to keep all other attributes of this xml file and change the gradiento n runtime programatically. I was told I can use StateListDrawable and GradientDrawable to do this. Here is my unsuccessful attemot:</p>
  
  <pre><code>TextView myTextView1 = ......
  StateListDrawable sld = new StateListDrawable();
  GradientDrawable drawable = new GradientDrawable();
  drawable.setColor(myColor);
  sld.addState(new int[] { android.R.attr.state_enabled }, drawable);
  myTextView1.setBackgroundDrawable(sld);
  </code></pre>
  
  <p>but this does not seem to be doinng anything. Am I doing this correctly?</p>