-1

I have a view item in my RecyclerAdapter's onBindViewHolder. Since setBackgroundColor is deprecated, what should I do instead?

holder.itemView.setBackgroundColor(mContext.getResources().getColor(bgColor));
Martin Erlic
  • 5,467
  • 22
  • 81
  • 153

1 Answers1

5

As getResources().getColor(bgColor) is depracated

Use below one

ContextCompat.getColor(this, R.color.bgcolor)
Preetika Kaur
  • 1,991
  • 2
  • 16
  • 23
  • But how does that work in relation to the view holder? I don't think this is a duplicate question. The answer doesn't solve the problem. ``holder.itemView.ContextCompat.getColor(this, R.color.bgColor);`` doesn't work. See what I mean? – Martin Erlic Sep 30 '16 at 13:06
  • 3
    holder.itemview.setBackgroundColor(ContextCompat.getColor(this, R.color.bgColor)); This will be your code – Preetika Kaur Sep 30 '16 at 16:48
  • @santafebound if it helps you can I get an upvote as well – Preetika Kaur Sep 30 '16 at 17:23