如何使用 RemoteViews 更改小部件背景?
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在
RelativeLayout
上调用setImageViewBitmap
。RelativeLayout
不是ImageView
。您可以在其中放置一个ImageView
来代替填充RelativeLayout
并对其进行调用。You're calling
setImageViewBitmap
on aRelativeLayout
. ARelativeLayout
is not anImageView
. You could put anImageView
in there instead that fills theRelativeLayout
and call it on that.