【问题标题】:How to have a string Bold into a textView with Kotlin?如何使用 Kotlin 将字符串 Bold 放入 textView?
【发布时间】:2020-09-02 08:33:14
【问题描述】:

我想用 Kotlin 将字符串 Bold 放入 textView,这是我的代码:

 val priceTxt = "10.000" ///example
    
    val s = SpannableStringBuilder()
                .append("starting from")
                .append(" ")
                .append(currency)
                .append(" ")
                .bold { append(priceTxt) }
     txtviewPrice.text = s

我想得到以下结果:"starting from $ 10.000"

我应该在我的代码中进行哪些更改以使其成为上面的示例?

【问题讨论】:

标签: android kotlin


【解决方案1】:

价格文本应该是 SpannableString

我建议您修改代码添加以下行:

val priceTxt = SpannableString("10.000")
priceTxt.setSpan(StyleSpan(Typeface.BOLD), 0, priceTxt.length)

.append(priceTxt)

给你的建造者

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多