如何在任何 Jetpack Compose 视图上禁用涟漪效应?
How to disable ripple effect on any Jetpack Compose view?
在 Jetpack Compose 中,如何消除(或更改形状)单击项目时的涟漪效果?
这是 NavigationBar
from Material Design 3
的示例
var selectedItem by remember { mutableStateOf(0) }
val items = listOf("Songs", "Artists", "Playlists")
NavigationBar {
items.forEachIndexed { index, item ->
NavigationBarItem(
icon = { Icon(Icons.Filled.Favorite, contentDescription = null) },
label = { Text(item) },
selected = selectedItem == index,
onClick = { selectedItem = index }
)
}
}
正在尝试添加 Modifier
和
modifier = Modifier.clickable(interactionSource = interactionSource,indication = null){}
在 NavigationBar
和 NavigationBarItem
上都不起作用。
您可以通过提供 LocalRippleTheme
来完成。 CompositionLocalProvider
content
内的所有视图都不会产生波纹。
CompositionLocalProvider(
LocalRippleTheme provides ClearRippleTheme
) {
NavigationBar {
items.forEachIndexed { index, item ->
NavigationBarItem(
icon = { Icon(Icons.Filled.Favorite, contentDescription = null) },
label = { Text(item) },
selected = selectedItem == index,
onClick = { selectedItem = index }
)
}
}
}
ClearRippleTheme
:
object ClearRippleTheme : RippleTheme {
@Composable
override fun defaultColor(): Color = Color.Transparent
@Composable
override fun rippleAlpha() = RippleAlpha(
draggedAlpha = 0.0f,
focusedAlpha = 0.0f,
hoveredAlpha = 0.0f,
pressedAlpha = 0.0f,
)
}
在 Jetpack Compose 中,如何消除(或更改形状)单击项目时的涟漪效果?
这是 NavigationBar
from Material Design 3
var selectedItem by remember { mutableStateOf(0) }
val items = listOf("Songs", "Artists", "Playlists")
NavigationBar {
items.forEachIndexed { index, item ->
NavigationBarItem(
icon = { Icon(Icons.Filled.Favorite, contentDescription = null) },
label = { Text(item) },
selected = selectedItem == index,
onClick = { selectedItem = index }
)
}
}
正在尝试添加 Modifier
和
modifier = Modifier.clickable(interactionSource = interactionSource,indication = null){}
在 NavigationBar
和 NavigationBarItem
上都不起作用。
您可以通过提供 LocalRippleTheme
来完成。 CompositionLocalProvider
content
内的所有视图都不会产生波纹。
CompositionLocalProvider(
LocalRippleTheme provides ClearRippleTheme
) {
NavigationBar {
items.forEachIndexed { index, item ->
NavigationBarItem(
icon = { Icon(Icons.Filled.Favorite, contentDescription = null) },
label = { Text(item) },
selected = selectedItem == index,
onClick = { selectedItem = index }
)
}
}
}
ClearRippleTheme
:
object ClearRippleTheme : RippleTheme {
@Composable
override fun defaultColor(): Color = Color.Transparent
@Composable
override fun rippleAlpha() = RippleAlpha(
draggedAlpha = 0.0f,
focusedAlpha = 0.0f,
hoveredAlpha = 0.0f,
pressedAlpha = 0.0f,
)
}