Reputation: 25
Good day, I'm trying to create a gradient over an image using color resource ids, it works when I type out Color.Transparent and Color.Green. However, when I try to use a list of colors using color resource ids such as color such as:
colors = listOf(colorResource(R.color.gradient1))
colorResource is underlined red
Here is what I'm trying to achieve:
[
LazyColumn(
modifier = Modifier.padding(it)
) {
item{
Box(
modifier = Modifier.height(200.dp).fillMaxWidth()
){
val coverPicture = detailList.firstOrNull()?.coverPicture ?: ""
Image(
painter = rememberImagePainter(coverPicture),
contentDescription = null,
modifier = Modifier
.fillMaxSize()
.drawWithCache {
val gradient = Brush.verticalGradient(
colors = listOf(Color.Transparent, Color.Green),
startY = size.height/3,
endY = size.height
)
onDrawWithContent {
drawContent()
drawRect(gradient, blendMode = BlendMode.Multiply)
}
},
contentScale = ContentScale.FillBounds
)
}
}
items(detailList) {
item ->
}
}
I tried using another box but I would like to use the drawWithCache as it is simpler. Right now, I'm using Color.Transparent and Color.Green but I'm not really satisfied with the result and would like to use my own colors. Any help is appreciated and Thank you in advance
Upvotes: 1
Views: 36
Reputation: 25
Nevermind, I just declared a list of color resource ids before the actual Lazycolumn and it worked!
Upvotes: 0