更改remoteView ImageView背景
我有一些带有 ImageViews 的 RemoteView,我需要以编程方式更改“android:background”。
我知道如何更改“android:src”:
remoteView.setImageViewResource(int viewId, int srcId);
并且它工作正常,但是如何更改“android:background”?
谢谢
I have some remoteView with ImageViews, and I need to change the "android:background" programmatically.
I know how to change the "android:src" with:
remoteView.setImageViewResource(int viewId, int srcId);
And it works fine, but how do I change the "android:background"?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 public void setInt(int viewId, String methodName, int value) 方法。
You can use
public void setInt (int viewId, String methodName, int value)
method.使用setBackgroundResource(int)。
另外,这里有一些你可能需要注意的事情。当您查看 Android 文档时,如果有您可以更改视图的 xml 元素,它通常指向在运行时进行更改的方法。
Use setBackgroundResource(int).
Also, here is something you may take note of. When you look at Android documentation, if there is an xml element for a View that you can change, it normally points to the method to make the change at runtime.
偷工减料的方式
我认为你可以使用偷工减料的方式做第二个布局与新的背景,然后你使用这个新的布局创建你的remoteView,如下所示:
毕竟,布局并没有那么昂贵。
The jerry-rig way
I think you could do it using the jerry-rig way doing a second layout with the new background, then you create your remoteView using this new layout, like this:
after all, a layout isn't so expensive.