Issue
This is how i create my button in compose
Button(
modifier = modifier,
enabled = enabled.value,
onClick = {}
) {
Text(text = text)
}
Solution
The background color of the Button
is based on the colors defined in the ButtonDefaults.buttonColors()
.
A workaround is to define the same color to disabledBackgroundColor
and backgroundColor
.
Something like:
var isButtonEnabled by remember { mutableStateOf(true) }
val animateStateButtonColor = animateColorAsState(
targetValue = if (isButtonEnabled) Color.Blue else Teal200,
animationSpec = tween(2000, 0, LinearEasing)
)
Button(
colors = ButtonDefaults.buttonColors(
backgroundColor = animateStateButtonColor.value,
disabledBackgroundColor = animateStateButtonColor.value,
),
enabled = isButtonEnabled,
onClick = { /* ... */ }
) {
Text(text = "Button")
}
Answered By - Gabriele Mariotti
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.