简体   繁体   English

Android小部件无法更改背景颜色

[英]Android widget can't change background color

I'm trying to change the background color of a ListView in an active widget on the fly like so, 我正在尝试像这样实时更改活动窗口小部件中ListView的背景颜色,

public static void updateWidgetTheme(Context context, int bgColor) {
    RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget);
    widget.setInt(R.id.listView, "setBackgroundColor", bgColor);
}

Which i'm calling from the Main activity of my app. 我是从我的应用程序的主活动中调用的。 There are active widgets. 有活动的小部件。 It seems to have no effect. 似乎没有作用。 I've read several questions where this is the appropriate way to change background color of a view in an active widget. 我已经阅读了几个问题,这是在活动小部件中更改视图背景颜色的适当方法。

Why isn't this working? 为什么这不起作用?

仅更改RemoteViews是不够的-您需要使用appWidgetId和更新后的RemoteViews调用AppWidgetManager.updateAppWidget()才能实际更新窗口小部件。

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

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