I want to change background color when user press ...
# compose
k
I want to change background color when user press on button. When I tried some piece of code it showing my some shadow color. I don't understand. Can someone guide me on this.
Button.kt
Copy code
CompositionLocalProvider(LocalRippleTheme provides NoRippleTheme()) {
        val interactionSource = remember { MutableInteractionSource() }
        val isPressed by interactionSource.collectIsPressedAsState()
        OutlinedButton(
            colors = ButtonDefaults.outlinedButtonColors(
                backgroundColor = if (isPressed) {
                    Aqua
                } else {
                    Color.Transparent
                }
            ),
            interactionSource = interactionSource,
            onClick = { onActionClick() },
            modifier = Modifier.fillMaxWidth(),
            border = BorderStroke(1.dp, Aqua),
            shape = RoundedCornerShape(4.dp)
        ) {
            Text(
                text = text,
                modifier = Modifier
                    .padding(8.dp),
                style = if (isPressed) {
                    WhiteTypography.h5
                } else {
                    AquaTypography.h5
                }
            )
        }
    }
NoRippleTheme.kt
Copy code
class NoRippleTheme : RippleTheme {

    @Composable
    override fun defaultColor() = Color.Unspecified

    @Composable
    override fun rippleAlpha(): RippleAlpha = RippleAlpha(0.0f, 0.0f, 0.0f, 0.0f)
}
I want to remove shadow when user tap on button.
As you can see below image have not shadow when user taps on it. This piece of code is xml based.
t
@KotlinLeaner Did you find a solution with Compose?
376 Views