https://kotlinlang.org logo
#compose
Title
# compose
d

deniskrr

02/25/2021, 9:19 PM
Hey 😄 Does anyone know how I can draw a transparent gradient over an image? I’m trying to achieve this: (there’s a black gradient starting from the bottom)
v

Vitor Prado

02/25/2021, 9:21 PM
gradient modifier:
Copy code
fun Modifier.verticalGradientBackground(colors: List<Color>, alpha: Float = 1f) =
    background(brush = Brush.verticalGradient(colors = colors), alpha = alpha)
layout:
Copy code
NetworkImage(
                collection.coverUrl,
                modifier = Modifier
                    .fillMaxWidth()
                    .aspectRatio(16f / 9f)
            )

            Box(modifier = Modifier
                .fillMaxWidth()
                .aspectRatio(16f / 9f)
                .verticalGradientBackground(
                    listOf(AppColors.leBleu, AppColors.gradientDarkColor),
                    alpha = .5f
                )
            )
👍 4
d

deniskrr

02/25/2021, 9:24 PM
Works 😄 Thank you very much @Vitor Prado
v

Vitor Prado

02/25/2021, 9:31 PM
you can write your own gradient modifier and use in all images.