mjimperial
mjimperial

Reputation: 25

Using color resource for a gradient over image

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: [enter image description here(https://i.sstatic.net/1V4Yun3L.png)

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

Answers (1)

mjimperial
mjimperial

Reputation: 25

Nevermind, I just declared a list of color resource ids before the actual Lazycolumn and it worked!

Upvotes: 0

Related Questions