如何使用RemoteViews更改窗口小部件背景?

时间:2012-01-20 01:26:13

标签: java android android-layout android-widget

<RelativeLayout
    android:id="@+id/widget"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/my_background"
    android:orientation="vertical" >

现在我想使用RemoteViews将此背景更改为“@ drawable / your_bck”。我试过这样的事情

Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.yout_bck);
remoteViews.setImageViewBitmap(R.id.widget, bitmap);

但我随后显示“Widget无法加载”

它必须作为背景,因为我需要在图像中心设置文本:)

1 个答案:

答案 0 :(得分:3)

您正在setImageViewBitmap上致电RelativeLayoutRelativeLayout不是ImageView。您可以在其中放置ImageView,而不是填充RelativeLayout并在其上调用它。

相关问题