1

I have learned how to set an ImageView's foreground colour programmatically here, but this sets the colour to a value in the R.color resource:

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

However, I would like to directly set a String hex value to the colour -- is there a way to accomplish this?

Paradox
  • 4,602
  • 12
  • 44
  • 88

1 Answers1

2

Use ColorDrawable with Color.parseColor("#FFFFFF") like so:

ColorDrawable cd = new ColorDrawable(Color.parseColor("#FFFFFF"));
        holder.image.setForeground(cd);
Paradox
  • 4,602
  • 12
  • 44
  • 88