'How to change ripple color alpha

I'm trying to modify the contrast of ripple color of the background of a Row when I click on it. So far this is how I modified the color of the background.

object GreenRippleTheme : RippleTheme {
    @Composable
    override fun defaultColor(): Color = FigmaPrimaryGreenDark

    @Composable
    override fun rippleAlpha(): RippleAlpha = RippleTheme.defaultRippleAlpha(
        Color.White,
        lightTheme = !isSystemInDarkTheme()
    )
}

Inside my theme:

  CompositionLocalProvider(
    LocalBaseScr provides colors,
) {
    MaterialTheme(
        colors = colors.material,
        content = content,
    )
}

The composable:

@Composable
fun ActionWidget() {
    CompositionLocalProvider(LocalRippleTheme provides GreenRippleTheme) {
        Row(
            modifier = Modifier
                .height(100.dp)
                .fillMaxWidth()
                .clickable(enabled = true,
                    onClick = {})
        )
        {}
    }
}

The background color on click changed, but how to deal with the contrast of the color?



Solution 1:[1]

You won't be able to change the ripple alpha if you use defaultRippleAlpha

Instead create a separate variable for alpha and use that. Sample working code

object BusinessAppRippleTheme : RippleTheme {

val alpha = RippleAlpha(
    focusedAlpha = 1f,
    draggedAlpha = 1f,
    hoveredAlpha = 1f,
    pressedAlpha = 1f
)

@Composable
override fun defaultColor() : Color = AppColor.Primary

@Composable
override fun rippleAlpha(): RippleAlpha = alpha 
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1