3

我已经在 Activity 中完成了此操作,并且效果很好。

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);

现在我想在一个小部件(内部onUpdate)中做同样的事情,我必须使用它RemoteViews来访问图像。

我如何setImageDrawable调用ImageViewfrom RemoteViews?所有远程视图方法似乎都需要一个Bitmap.

4

3 回答 3

15

您可以通过执行以下操作更改“RemoteViews”中 ImageView 图像的颜色:

remoteviews.setInt(viewid, "setColorFilter", color);
于 2013-03-24T11:59:44.703 回答
3
after modify drawable :



 Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
 remoteViews.setImageViewBitmap(viewId, bitmap) .
于 2011-11-13T17:15:19.940 回答
2

RemoteViews是从 XML 资源描述符构建的。您不能使用代码来构建它们。

你需要做这样的事情:

创建布局:

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

然后定义一个名为(在 res/drawables 文件夹中)的新形状可绘制对象:myshapedrawable.xml

<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>
于 2011-11-13T17:25:23.373 回答