为什么指示不适用于按钮或图标?
Why don't Indication work for Button or Icons?
作为,我通过将indication
设置为null
来禁用水龙头闪烁。
但是,这不适用于按钮或图标?!
您可以使用
Modifier.pointerInput(Unit) {
detectTapGestures(
onPress = { /* Called when the gesture starts */ },
onDoubleTap = { /* Called on Double Tap */ },
onLongPress = { /* Called on Long Press */ },
onTap = { /* Called on Tap */ }
)
}
代替onClick()
。点击按钮时不会显示波浪效果。
在 Button
中,您不能在 clickable
修饰符中使用 indication=null
,因为它是由使用 indication = rememberRipple()
的组件在内部定义的。这将使用 RippleTheme
.
提供的值创建并记住 Ripple
您可以提供自定义 LocalRippleTheme
来覆盖默认行为。
类似于:
CompositionLocalProvider(LocalRippleTheme provides NoRippleTheme) {
Button(
onClick = { /*...*/ },
) {
//...
}
}
与:
private object NoRippleTheme : RippleTheme {
@Composable
override fun defaultColor() = Color.Unspecified
@Composable
override fun rippleAlpha(): RippleAlpha = RippleAlpha(0.0f,0.0f,0.0f,0.0f)
}
作为indication
设置为null
来禁用水龙头闪烁。
但是,这不适用于按钮或图标?!
您可以使用
Modifier.pointerInput(Unit) {
detectTapGestures(
onPress = { /* Called when the gesture starts */ },
onDoubleTap = { /* Called on Double Tap */ },
onLongPress = { /* Called on Long Press */ },
onTap = { /* Called on Tap */ }
)
}
代替onClick()
。点击按钮时不会显示波浪效果。
在 Button
中,您不能在 clickable
修饰符中使用 indication=null
,因为它是由使用 indication = rememberRipple()
的组件在内部定义的。这将使用 RippleTheme
.
Ripple
您可以提供自定义 LocalRippleTheme
来覆盖默认行为。
类似于:
CompositionLocalProvider(LocalRippleTheme provides NoRippleTheme) {
Button(
onClick = { /*...*/ },
) {
//...
}
}
与:
private object NoRippleTheme : RippleTheme {
@Composable
override fun defaultColor() = Color.Unspecified
@Composable
override fun rippleAlpha(): RippleAlpha = RippleAlpha(0.0f,0.0f,0.0f,0.0f)
}