title: Modify the gradient of a shape drawable in code in Android
body: <p>I've been scouring the web and SO but still no luck.</p>
  
  <p>Problem:</p>
  
  <p>App connects to a server to retrieve a few colours that are then assigned to various controls in the app.</p>
  
  <p>My problem is that I'd like to use style defined in xml for Edittext and Button controls, but if i set the background colour of the control it removes any of my predefined styling.</p>
  
  <p>I have a selector drawable with defined styles for pressed, focused and normal</p>
  
  <p>How can I modify the gradient within the selector from code.</p>
  
  <p>Please note: it is a requirement that the colour comes from the server, (which is just a hex value)</p>
  
  <p>main (JAVA)</p>
  
  <pre><code>int gradientColour1= "comes from server"
  int gradientColour2= "also comes from server"
  
  Button btnNext = (Button)findViewById(R.id.btnnext);
  btnNext.setBackgroundColor(gradientColor1);
  </code></pre>
  
  <p>is there a way I can do something like this: (pseudo)</p>
  
  <pre><code>Gradient grad = new Gradient(gradientColor1,gradientColor2,90);
  btnNext.setBackgroundGradient(grad);
  btnNext.setBorderRadius(15);
  </code></pre>
  
  <p>I need to be able to get the colours via a webrequest, not predefined in xml</p>
  
  <p>There must be a way that I can do this.
  If I have to do away with the pre-defined styles then that's fine.</p>
  
  <p>I'm pretty new to android/java and Stack Overflow so please be gentle
  Thanks in advance </p>