title: Android: Change shape color programmatically for widget
body: <p>I'm trying to change color of the shape for my widget programmatically.</p>
  
  <p>My widget layout looks like this:</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
      &lt;ImageButton
          android:id="@+id/button"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:adjustViewBounds="true"
          android:background="@drawable/transparent_color"
          android:clickable="true"
          android:focusable="true"
          android:padding="8dp"
          android:scaleType="fitCenter"
          android:src="@drawable/btn03_off" /&gt;
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>In my settngs activity, I'm changing background shape and image programmatically. And I need to change the color of the shape too.</p>
  
  <pre><code> views.setInt(R.id.button, "setBackgroundResource", R.drawable.rounded_conners);
   views.setImageViewResource(R.id.button, mImageResId);
  </code></pre>
  
  <p>I can't figure out how to set color to the shape for my widget. I can do it in activity like this:</p>
  
  <pre><code> ((GradientDrawable) mPreviewImageView.getBackground()).setColor(colorId);
  </code></pre>
  
  <p>But this is not working with widget, because I have no reference to my button.</p>
  
  <p>Thank you </p>