Jetpack Compose 中的未绑定波纹/指示(相当于 selectableBackgroundBorderless) [英] Unbound Ripple/Indication in Jetpack Compose (equivalent to selectableBackgroundBorderless)

查看:20
本文介绍了Jetpack Compose 中的未绑定波纹/指示(相当于 selectableBackgroundBorderless)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Jetpack Compose 中,clickable 修饰符将默认使用 LocalIndication.current 并显示绑定到边框的波纹.这几乎总是看起来很棒,但在某些情况下,圆形、无约束的波纹看起来更好.回到 View Android,我们会使用 android:background="?attr/selectableItemBackgroundBorderless 来实现这种行为.我们如何在撰写中做到这一点?

示例[来源]::>

解决方案

您可以自定义涟漪效果如下:

Modifier.clickable(交互源 = 记住 { MutableInteractionSource() },indication = rememberRipple(bounded = false),//你也可以改变波纹的颜色和半径onClick = {})

In Jetpack Compose the clickable Modifier will by default use LocalIndication.current and show a ripple that is bound to the border. That looks great almost always, but there are some circumstances where a rounded, unbound ripple looks better. Back in View Android we would've used android:background="?attr/selectableItemBackgroundBorderless to achieve this behaviour. How can we do it in compose?

Example [source]:

解决方案

You can customise the ripple effect as follow:

Modifier.clickable(
    interactionSource = remember { MutableInteractionSource() },
    indication = rememberRipple(bounded = false), // You can also change the color and radius of the ripple
    onClick = {}
)

这篇关于Jetpack Compose 中的未绑定波纹/指示(相当于 selectableBackgroundBorderless)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆