Ste*_*one 4 android android-layout kotlin material-components-android android-jetpack-compose
在Jetpack Compose中,如何在单击某个项目时删除(或更改其形状)涟漪效果?
这是Material Design 3NavigationBar中的一个示例
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 }
)
}
}
Run Code Online (Sandbox Code Playgroud)
尝试添加一个Modifierwith
modifier = Modifier.clickable(interactionSource = interactionSource,indication = null){}
Run Code Online (Sandbox Code Playgroud)
无论是在 上NavigationBar还是在 上NavigationBarItem,都不起作用。
Phi*_*hov 12
您可以通过提供来做到这一点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 }
)
}
}
}
Run Code Online (Sandbox Code Playgroud)
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,
)
}
Run Code Online (Sandbox Code Playgroud)