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
With CardView in Kotlin
internal fun bind(d: Detalle, position: Int, listener: OnItemClickListener) {
if (position % 2 == 1) {
cardViewPrincipal.setCardBackgroundColor(ContextCompat.getColor(itemView.context, R.color.blue_logo))
} else {
cardViewPrincipal.setCardBackgroundColor(ContextCompat.getColor(itemView.context, R.color.colorWhite))
}
Multiples Colors
when {
p % 4 == 0 -> cardViewPrincipal.setCardBackgroundColor(ContextCompat.getColor(itemView.context, R.color.yellow))
p % 4 == 1 -> cardViewPrincipal.setCardBackgroundColor(ContextCompat.getColor(itemView.context, R.color.green))
p % 4 == 2 -> cardViewPrincipal.setCardBackgroundColor(ContextCompat.getColor(itemView.context, R.color.blue))
p % 4 == 3 -> cardViewPrincipal.setCardBackgroundColor(ContextCompat.getColor(itemView.context, R.color.red))
}