[英]Android Jetpack Compose: Ripple effect is not working when using clickable
I used this example from android docs:我使用了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 }
)
}
This is how I'm using it in my App:这就是我在我的应用程序中使用它的方式:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Lemon_treeTheme {
ClickableSample()
}
}
}
}
The ripple effect is not working as expected.涟漪效应未按预期发挥作用。 I tried applying the clickable modifier to various elements such as Box and Row but it's not working as well.
我尝试将 clickable 修饰符应用于各种元素,例如 Box 和 Row,但效果不佳。 It works only with clickable elements such as Button.
它仅适用于可点击的元素,例如 Button。 What am I doing wrong?
我究竟做错了什么?
The default ripple is clipped by the bounds of the target layout.默认波纹被目标布局的边界裁剪。
You can override it specifying a custom indication with bounded = false
:您可以使用
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.