set foreground color in FrameLayout in android programmatically

风格不统一 提交于 2019-12-22 03:15:10

问题


I want to set foreground color in FrameLayout pragmatically (not in XML attribute). I have the color codes in RGB

How can I convert color to drawable...

frm.setForeground(Drawable);

Help!! Thanks


回答1:


You can create a Drawable from color:

final int color = 0xFFFF0000;
final Drawable drawable = new ColorDrawable(color);



回答2:


Create Drawable from Color Using ContextCompat

int color = R.color.black_trans_60;
frm.setForeground(new ColorDrawable(ContextCompat.getColor(mContext, color)));

Use ContextCompat instead of direct color as in new API ColorDrawable takes ColorDrawable(@ColorInt int color)



来源:https://stackoverflow.com/questions/14474745/set-foreground-color-in-framelayout-in-android-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!