title: Android Change Widget Background Image
body: <p>Been struggling for the past two days to change the background of my widget, based on some if statements (removed right now just want to change the widget background from the class) here is my source below. What's up though, I've changed images before fine such as backgrounds but can not get it to work for my widget thank you. This is my most recent attempt by the way</p>
  
  <pre><code>//Widget Provider Class
  public class WidgetProvider extends AppWidgetProvider {
  
      public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
          final int N = appWidgetIds.length;
  
          for (int i=0; i&lt;N; i++) {
              int appWidgetId = appWidgetIds[i];
  
              Intent intent = new Intent(context, com.widget.WidgetDialog.class);
              PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
  
              RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
              views.setOnClickPendingIntent(R.id.widget, pendingIntent);
  
              appWidgetManager.updateAppWidget(appWidgetId, views);
              views.setImageViewBitmap(R.id.widget, ((BitmapDrawable)context.getResources().getDrawable(R.drawable.widget_background)).getBitmap());
  
          }
      }
  }
  
  
  
  //Widget Layout XML
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      &gt;
      &lt;Button android:id="@+id/widget"
      android:background="#00000000"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
      &lt;/Button&gt;
  &lt;/LinearLayout&gt;
  </code></pre>