如何在jetpack compose中突出显示文本的特定单词? [英] How to highlight specific word of the text in jetpack compose?

查看:28
本文介绍了如何在jetpack compose中突出显示文本的特定单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在 jetpack compose 中突出显示文本的特定部分.我像这样尝试了 Html.fromHtml()

Text(text = Html.fromHtml(" 

但是没有用.有什么办法可以在撰写中做到这一点吗?

解决方案

使用 1.0.x 你可以使用

I wanted to know how to highlight the specific part of the text in jetpack compose. I tried Html.fromHtml() like this

Text(text = Html.fromHtml(" <font color='red'> Hello </font> World").toString())

But it didn't work. Is there any way I can do this in compose?

解决方案

With 1.0.x you can use the AnnotatedString to display the text with multiple styles.

Something like:

Text(buildAnnotatedString {
    withStyle(style = SpanStyle(color = Color.Red)) {
        append("Hello")
    }
    append(" World ")
})

这篇关于如何在jetpack compose中突出显示文本的特定单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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