How can I set a shape defined in xml as background of an image in a widget? Here are my attempts:
RemoteViews views = new RemoteViews(c.getPackageName(), R.layout.widget_layout);
Drawable dr = getResources().getDrawable(R.drawable.widgetshape); //class cast exception
Bitmap bp = ((BitmapDrawable)dr).getBitmap();
views.setImageViewBitmap(R.id.ImageView01, bp);
This results in an android.graphics.drawable.GradientDrawable class cast exception.
Bitmap icon = BitmapFactory.decodeResource(WidgetConfig.this.getResources(), R.drawable.widgetshape);
views.setImageViewBitmap(R.id.ImageView01, icon);
This throws a NullPointerException error on the awm.updateAppWidget(awID, views);
line.
Bitmap bp = ((BitmapDrawable)this.getResources().getDrawable(R.drawable.widgetshape)).getBitmap(); //Class Cast Exception
views.setImageViewBitmap(R.id.ImageView01, bp);
This results in an android.graphics.drawable.GradientDrawable class cast exception on the first line.