【发布时间】:2019-07-11 09:28:37
【问题描述】:
我按照github上的示例代码做了一个Widget:LoremWidget。
我想为每个项目设置不同的背景颜色(不是随机的)。 我想在该行下方设置背景颜色:
row.setTextViewText(R.id.widget_row_title, items[position].title)
// I want to do something similar like:
// row.findViewById<LinearLayout>(R.id.widget_row_root).setBackgroundColor = ...
我要设置的颜色是"#e57373"这样的字符串形式
----编辑----
为了更好地理解问题,在数据提供者类中为小部件设置背景颜色没有这样的方法:
public class LoremViewsFactory implements RemoteViewsService.RemoteViewsFactory {
@Override
public RemoteViews getViewAt(int position) {
// no method available for setting background color
【问题讨论】:
-
这就是问题所在,我不能为小部件做到这一点
-
行是您的视图。喜欢:row.setBackgroundColor(Color.parseColor("#ffffff"));
-
是的,但是在小部件类的情况下这是不可能的,请参阅示例代码