繁体   English   中英

Android Jetpack Compose:使用可点击时波纹效果不起作用

[英]Android Jetpack Compose: Ripple effect is not working when using clickable

我使用了android文档中的这个 例子

@Composable
fun ClickableSample() {
    val count = remember { mutableStateOf(0) }
    // content that you want to make clickable
    Text(
    text = count.value.toString(),
    modifier = Modifier.clickable { count.value += 1 }
    )
}

这就是我在我的应用程序中使用它的方式:

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Lemon_treeTheme {
                ClickableSample()
            }
        }
    }
}

涟漪效应未按预期发挥作用。 我尝试将 clickable 修饰符应用于各种元素,例如 Box 和 Row,但效果不佳。 它仅适用于可点击的元素,例如 Button。 我究竟做错了什么?

默认波纹被目标布局的边界裁剪。

您可以使用bounded = false指定自定义指示来覆盖它:

val interactionSource = remember { MutableInteractionSource() }

Text(
    text = count.value.toString(),
    modifier = Modifier
        .clickable(
            interactionSource = interactionSource,
            indication = rememberRipple(bounded = false)
        ) { count.value += 1 }
)

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM