这是我如何在compose中创建按钮
Button( modifier = modifier, enabled = enabled.value, onClick = {} ) { Text(text = text) }
h4cxqtbf1#
Button的背景色基于ButtonDefaults.buttonColors()中定义的颜色。解决方法是为disabledBackgroundColor和backgroundColor定义相同的颜色。比如:
Button
ButtonDefaults.buttonColors()
disabledBackgroundColor
backgroundColor
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") }
1条答案
按热度按时间h4cxqtbf1#
Button
的背景色基于ButtonDefaults.buttonColors()
中定义的颜色。解决方法是为
disabledBackgroundColor
和backgroundColor
定义相同的颜色。比如: