How to give alternate colors to rows in RecyclerView

In Recyclerview in Android we may want to give alternate colors to the rows. I will show you an easy way to do that, just put the below code in onBindViewHolder of the adapter class

if(position %2 == 1)
{
holder.itemView.setBackgroundColor(Color.parseColor("#E1F7F7F7"));
// holder.imageView.setBackgroundColor(Color.parseColor("#FFFFFF"));
}
else
{
holder.itemView.setBackgroundColor(Color.parseColor("#FFFFFF"));
// holder.imageView.setBackgroundColor(Color.parseColor("#FFFAF8FD"));
}

Share on Google Plus

About Admin

I am a Java and Android developer and a science enthusiast.I Like to explain complex things in simple language so anybody even without a graduation in computer science or Electronics can understand the concepts easily.

0 comments:

Post a Comment