Jude Cooray
Jude Cooray

Reputation: 19862

Call setImageDrawable from RemoteViews

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.

Upvotes: 4

Views: 8856

Answers (3)

E Player
E Player

Reputation: 1856

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

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

Upvotes: 16

Peter Knego
Peter Knego

Reputation: 80340

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:

<ImageView android:src="@drawable/myshapedrawable">
</ImageView>

Then define a new shape drawable named myshapedrawable.xml (in res/drawables folder):

<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="oval">
    <size android:width="200" android:height="100"/>
    <solid android:color="0xff74AC23"/>
</shape>

Upvotes: 3

Shailendra Singh Rajawat
Shailendra Singh Rajawat

Reputation: 8242

after modify drawable :



 Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
 remoteViews.setImageViewBitmap(viewId, bitmap) .

Upvotes: 3

Related Questions