set foreground color in FrameLayout in android programmatically

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

Answers


You can create a Drawable from color:

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

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)


Need Your Help

How Refactor Code/DB schema with EF 4 code first - Data Migration

c# entity-framework ef4-code-only

What are the best practices for database refactoring with codefirst EF4?

Is 'sub' claim part of openid scope or profile scope?

openid-connect identityserver3

As per the OpenID Connect specification is sub claim part of openid scope or profile scope? I could not find that information