title: How to modify color of a drawable programatically
body: <p>Hi I have a shape drawable in xml and it is used as background of a view. Its color needs to be changed in the code depending on conditions.</p>
  
  <p>So I am doing </p>
  
  <pre><code>  ShapeDrawable d =  (ShapeDrawable) getResources().getDrawable(R.drawable.shape1);
  
    d.getPaint().setShader(sd1);
  </code></pre>
  
  <p>but the getDrawable returns a gradient  drawable, casting it to ShapeDrawable generates error.</p>
  
  <p>So how can I get shapeDrawable in code and modify its attributes.</p>