Call setImageDrawable from RemoteViews

Ranhiru Jude Cooray picture Ranhiru Jude Cooray · Nov 13, 2011 · Viewed 7.4k times · Source

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.

Answer

E Player Plus picture E Player Plus · Mar 24, 2013

You can change color of ImageView image in "RemoteViews" by doing this:

remoteviews.setInt(viewid, "setColorFilter", color);