You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Android Jetpack Compose中为Text组件添加删除线效果

Android Jetpack Compose Text组件添加删除线实现方案

你可以通过Text组件的style参数配置textDecoration属性实现删除线效果,对应配置项为TextDecoration.LineThrough,修改后的代码如下:

Text(
    "$863",
    fontSize = 24.sp,
    modifier = Modifier.width(IntrinsicSize.Min),
    maxLines = 1,
    style = TextStyle(textDecoration = TextDecoration.LineThrough)
)

如果有其他扩展需求可以参考以下实现:

  • 同时组合多种文本装饰(例如下划线+删除线):
style = TextStyle(
    textDecoration = TextDecoration.combine(
        listOf(TextDecoration.LineThrough, TextDecoration.Underline)
    )
)
  • 仅给文本的局部内容加删除线,使用AnnotatedString实现:
Text(
    text = buildAnnotatedString {
        append("原价 ")
        withStyle(SpanStyle(textDecoration = TextDecoration.LineThrough)) {
            append("$863")
        }
        append(" 特惠价 $599")
    },
    fontSize = 24.sp,
    maxLines = 1
)

内容的提问来源于stack exchange,提问作者Luis Aguilar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 14:24:03