ritesh
04/13/2022, 8:27 AMval lits1 = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val list2 = listOf("one", "two", "three", "four", "five")
LazyRow {
// first
itemsIndexed(items = lits1) { _, item ->
Text(text = "$item")
}
// second
itemsIndexed(items = list2) { _, item ->
Text(text = item, modifier = Modifier.background(Green))
}
}
Instead of giving background to each items in list2
, is it possible to give the whole list items as a background in second
itemsIndexed
. I couldn't think of any other solution than this.f.babic
04/13/2022, 8:29 AMLazyRow
that has a background, if that's what you're saying.ritesh
04/13/2022, 8:34 AM// second
itemsIndexed(items = list2) { _, item ->
Text(text = item, modifier = Modifier.background(Green))
}
Each item here, should have a different background, i was wondering instead of passing background to each Text
- is there a better way -like wrap it as a whole inside a Surface or something. But I guess i won't be able to as it needs to be called from Composable
and also to access itemsIndexed
items
it needs LazyListScope
Just curious if there is a way to do it, above solution works for me though!theapache64
04/13/2022, 8:34 AMRow
inside items
and use two Text
or one annotatedString
ritesh
04/13/2022, 8:44 AMLazyRow
controls the scroll behaviour of the items laid out and you can have as many itemsIndexed
or items
inside its scope. Or may be i am missing something?f.babic
04/13/2022, 8:45 AMclass MyData(val text: String, val color: Color)
and then pass that so you color each item differentlyritesh
04/13/2022, 8:50 AMText(text = item, modifier = Modifier.background(Green))
Also, it can be just a string or a different composable with Strings and other things altogether!ritesh
04/13/2022, 8:53 AMComposable
, instead use a wrapper and give it a background in above scenario for second itemsIndexed
or say for list2.Chris Sinco [G]
04/13/2022, 9:58 AMritesh
04/13/2022, 10:06 AMText
, but it can be anything. The list2 (the one in green), that can be achieved by giving background as green to each and every item in list2. I was wondering instead of giving background to each item composable, can it be just given to the whole list2 items, as in can it be wrapped in a Surface or so and give it background.Chris Sinco [G]
04/13/2022, 10:30 AMChris Sinco [G]
04/13/2022, 10:32 AMChris Sinco [G]
04/13/2022, 10:33 AMritesh
04/13/2022, 10:34 AMtheapache64
04/13/2022, 8:17 PMritesh
04/13/2022, 8:18 PM