如何使用自定义样式更改 TextDecoration.Underline?

Jee*_*cha 8 android android-jetpack-compose android-compose-textfield

我想将自定义下划线样式应用于带下划线的文本。我们可以在里面改变吗TextDecoration.underline

textStyle = MaterialTheme.typography.titleMedium.copy(
    textAlign = TextAlign.Start,
    fontWeight = FontWeight.W600,
    color = color,
    textDecoration = TextDecoration.Underline
)
Run Code Online (Sandbox Code Playgroud)

Gab*_*tti 15

textDecoration = TextDecoration.Underline您可以简单地在 的底部画一条线,而不是使用Text

就像是:

Text(
    modifier = Modifier.drawBehind {
        val strokeWidthPx = 1.dp.toPx()
        val verticalOffset = size.height - 2.sp.toPx()
        drawLine(
            color = Teal200,
            strokeWidth = strokeWidthPx,
            start = Offset(0f, verticalOffset),
            end = Offset(size.width, verticalOffset)
        )
    },
    text = text,
)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

如果您的行数Text超过 1 行,则必须计算文本高度并为每行文本绘制线条。