我正在努力实现的目标:
int[] colors = new int[]{colorDark,colorLight}
GradientDrawable gd = new GradientDrawable(TOP_BOTTOM, colors);
remoteView.setBackgroundDrawable(gd); //method does not exist
显然这是不可能的。
我怎样才能做到这一点?(如果它是可能的)
我不想在 xml 文件中为不同的颜色创建多个形状,因为这限制了选项。
我尝试将我的可绘制对象转换为位图并调用setImageViewBitmap
。我转换为这段代码 https://stackoverflow.com/a/10600736/802469并使用这段代码 https://stackoverflow.com/a/1016941/802469获取宽度/高度,但我无法填充小部件(此外,设备的显示宽度/高度确实不是我需要的)
我只是猜测。您可以尝试扩展 RemoteViews 并覆盖 apply 函数吗:
public class MySpecialRemoteViews extends RemoteViews {
//add the Constructors
public View apply(Context context, ViewGroup parent) {
View result = super.apply(context, parent);
//your code
int[] colors = new int[]{colorDark,colorLight}
GradientDrawable gd = new GradientDrawable(TOP_BOTTOM, colors);
result.setBackgroundDrawable(gd);
//end of your code
return result;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)