简体   繁体   English

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

[英]How to change widget background using RemoteViews?

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

And now I want to change this background to "@drawable/your_bck" using RemoteViews. 现在我想使用RemoteViews将此背景更改为“@ drawable / your_bck”。 I tried something like this 我试过这样的事

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

But i then it shows "Widget failed to load" 但我随后显示“Widget无法加载”

It must be as a background because i need to set a text on the center of image :) 它必须作为背景,因为我需要在图像的中心设置一个文本:)

You're calling setImageViewBitmap on a RelativeLayout . 你在RelativeLayout上调用setImageViewBitmap A RelativeLayout is not an ImageView . RelativeLayout不是ImageView You could put an ImageView in there instead that fills the RelativeLayout and call it on that. 您可以在其中放置一个ImageView ,而不是填充RelativeLayout并在其上调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM