In Android RecyclerView How to change the color of Alternate rows

前端 未结 6 2151
南笙
南笙 2021-02-05 11:45

I am new in android , recently I have learned recyclerview and i want to change the color of rows.

Example: I have 10 rows and I want to change color like

6条回答
  •  别那么骄傲
    2021-02-05 12:02

    You can change the color of alternate row by adding the following code on your Adapter class. You can also change the images of your row by using this code.

    Put this code inside OnBindViewHolder in Adapter Class.

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

提交回复
热议问题