how to alternate colours in two diferent texts in a LazyColumn column Text. Follow the code below
LazyColumn(/*contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp),*/
modifier = Modifier.fillMaxSize()
) {
items(50) {index ->
Text("R$ 120,00/UN", fontSize = 13.sp,
color = if(selectd==index) colorResource(id = R.color.red)
else colorResource(id = R.color.white),
modifier = Modifier
.border(1.dp, Color.LightGray, RoundedCornerShape(4.dp))
.background(if(selectd==index) colorResource(id = R.color.pastel_green)
else colorResource(id = R.color.cinza))
.padding(5.dp)
.clickable { selectd=index})
Text("R$ 120,00/KG", fontSize = 13.sp,
color = if(selectd==index) colorResource(id = R.color.red)
else colorResource(id = R.color.white),
modifier = Modifier.border(1.dp, Color.LightGray, RoundedCornerShape(4.dp))
.background(if(selectd==index) colorResource(id = R.color.pastel_green)
else colorResource(id = R.color.cinza))
.padding(5.dp)
.clickable { selectd=index})
}
}
You can use
itemsIndexed
instead ofindex
.Something like: