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

发布于 2024-12-28 02:58:57 字数 534 浏览 0 评论 0原文

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

,但随后它显示“小部件无法加载”

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

<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. 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"

It must be as a background because i need to set a text on the center of image :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聆听风音 2025-01-04 02:58:57

您正在 RelativeLayout 上调用 setImageViewBitmapRelativeLayout 不是 ImageView。您可以在其中放置一个 ImageView 来代替填充 RelativeLayout 并对其进行调用。

You're calling setImageViewBitmap on a RelativeLayout. A RelativeLayout is not an ImageView. You could put an ImageView in there instead that fills the RelativeLayout and call it on that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文