In Android RecyclerView How to change the color of Alternate rows

前端 未结 6 2153
南笙
南笙 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:20

    Using Kotlin

        if (position % 2 == 1) {
            holder?.itemView?.setBackgroundColor(context.resources.getColor(R.color.text_gray))
        } else {
            holder?.itemView?.setBackgroundColor(context.resources.getColor(R.color.white))
        }
    

提交回复
热议问题