现在 (1.x.y
) the FloatingActionButton
不支持enabled
财产。
作为解决方法,您可以使用Button
with a CircleShape
.
var enabled by remember { mutableStateOf(false) }
Button(
onClick = { /* do something */},
modifier = Modifier.defaultMinSize(minWidth = 56.dp, minHeight = 56.dp),
enabled = enabled,
shape = CircleShape
){
Icon(Icons.Filled.Favorite, contentDescription = "Localized description")
}
如果你想使用FloatingActionButton
你可以这样做:
var enabled by remember { mutableStateOf(false) }
CompositionLocalProvider(LocalRippleTheme provides
if (enabled) LocalRippleTheme.current else NoRippleTheme) {
FloatingActionButton(
backgroundColor = if (enabled) MaterialTheme.colors.secondary else Gray,
onClick = { if (enabled) { /* do something */ } else {} },
) {
Icon(Icons.Filled.Favorite,
contentDescription = "Localized description",
tint = if (enabled)
LocalContentColor.current.copy(alpha = LocalContentAlpha.current)
else DarkGray)
}
}
with:
private object NoRippleTheme : RippleTheme {
@Composable
override fun defaultColor() = Color.Unspecified
@Composable
override fun rippleAlpha(): RippleAlpha = RippleAlpha(0.0f, 0.0f, 0.0f, 0.0f)
}