I have done this in an Activity and it works perfectly.
ImageView myImage = (ImageView) findViewById(R.id.myImageView);
ShapeDrawable mDrawable;
mDrawable = new ShapeDrawable(new OvalShape());
mDrawable.getPaint().setColor(0xff74AC23);
mDrawable.setBounds(x, y, x + width, y + height);
mDrawable.setIntrinsicWidth(width);
mDrawable.setIntrinsicHeight(height);
myImage.setImageDrawable(mDrawable);
Now I want to do the same thing in a widget (inside onUpdate
) and I have to use RemoteViews
to access the image.
How do I call the setImageDrawable
of an ImageView
from RemoteViews
? All the remote views methods seems to take a Bitmap
.
You can change color of ImageView image in "RemoteViews" by doing this:
RemoteViews
are built from XML resource descriptors. You can not use code to build them.You need to do something like this:
Create a layout:
Then define a new shape drawable named
myshapedrawable.xml
(in res/drawables folder):