Jetpack compose bold only string placeholder(Jetpack仅使用粗体组成字符串占位符)
问题描述
我有一个这样的字符串资源
<string name="my_string">Fancy string with an %1$s placeholder</string>
我希望将以下内容作为输出:";带有令人惊叹的占位符";的花哨字符串。它是占位符内容以粗体显示的字符串。
如何获得所需的输出?
推荐答案
最终我使用
获得了预期的结果val placeholder = "Amazing"
val globalText = stringResource(id = R.string.my_string, placeholder)
val start = globalText.indexOf(placeholder)
val spanStyles = listOf(
AnnotatedString.Range(SpanStyle(fontWeight = FontWeight.Bold),
start = start,
end = start + placeholder.length
)
)
Text(text = AnnotatedString(text = globalText, spanStyles = spanStyles))
这篇关于Jetpack仅使用粗体组成字符串占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!