如何在 Jetpack compose 中对文本使用视觉转换?

Cin*_*com 3 android-jetpack-compose

我需要在 Text 中实现视觉转换,但不知何故 Text 没有此参数,只有 TextFiled 有此参数。如何找到解决这个问题的方法?

例子;

TextField(
    visualTransformation = // have this parameter
)

Text(
    visualTransformation = // doesnt have this parameter
)
Run Code Online (Sandbox Code Playgroud)

我需要它,因为我必须显示大十进制包含逗号和点分隔符,并且我对此进行了视觉转换。

Dan*_*aga 6

您可以使用自定义VisualTransformation类来转换文本,然后再将其传递到Text.

val visualTransformation = remember { CustomVisualTransformation() }
val transformedText = remember(value) {
    visualTransformation.filter(AnnotatedString(value))
}.text

Text(text = transformedText)
Run Code Online (Sandbox Code Playgroud)