在 Jetpack Compose 中移动滑块时如何消除拖动效果

How to remove drag effect when moving a Slider in Jetpack Compose

我想从滑块刻度中删除拖动效果并移动它。 我不想在下图中出现这个淡紫色的圆圈。

我知道 Slider 组件中的 interactionSource 参数,但我没有正确处理它以 remove/disabled 拖动效果。

这是我的实际代码:

var sliderWeight by remember { mutableStateOf(0f) }
Text(text = sliderWeight.toString())
Slider(value = sliderWeight, onValueChange = { sliderWeight = it }, interactionSource = remember { MutableInteractionSource() })

没有定义光晕颜色或光晕半径的参数,但您可以提供自定义 LocalRippleTheme 来覆盖默认行为。

类似于:

CompositionLocalProvider(LocalRippleTheme provides NoRippleTheme) {
    Slider(
        value = sliderWeight,
        onValueChange = { sliderWeight = it },
    )
}

private object NoRippleTheme : RippleTheme {
    @Composable
    override fun defaultColor() = Color.Unspecified

    @Composable
    override fun rippleAlpha(): RippleAlpha = RippleAlpha(0.0f,0.0f,0.0f,0.0f)
}