Search code examples
androidgradientandroid-jetpackandroid-jetpack-compose

Android Jetpack compose gradient


Is it possible to draw a gradient over an image drawable using Jetpack Compose?

fun HeroCover() {
    Column {
        val image = +imageResource(R.drawable.edge_of_tomorrow_poster)
        Container(modifier = Height(440.dp) wraps Expanded) {
            Clip(shape = RoundedCornerShape(8.dp)) {
                DrawImage(image = image)
            }
        }
    }
}

I want to have a translucent gradient drawn on top of the image.


Solution

  • Try this:

    Box(
        modifier = Modifier
            .background(
                brush = Brush.verticalGradient(
                    colors = listOf(
                        MaterialTheme.colors.primary,
                        MaterialTheme.colors.primaryVariant
                    )
                )
            )
    ) {
        Content()
    }