![](/img/trans.png)
[英]Android: Set margins in a FrameLayout programmatically- not working
[英]set foreground color in FrameLayout in android programmatically
我想在实际上在FrameLayout中设置前景色(而不是在XML属性中)。 我有RGB
的颜色代码
如何将颜色转换为可绘制的...
frm.setForeground(Drawable);
救命!! 谢谢
您可以从颜色创建Drawable
:
final int color = 0xFFFF0000;
final Drawable drawable = new ColorDrawable(color);
使用ContextCompat
从颜色创建Drawable
int color = R.color.black_trans_60;
frm.setForeground(new ColorDrawable(ContextCompat.getColor(mContext, color)));
在新API中使用ContextCompat
而不是直接颜色ColorDrawable
采用ColorDrawable(@ColorInt int color)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.