我需要用简单的标记渲染一些文本 <b> <i>
等等,它看起来像 this应该可以显示它,但我想知道是否可以将带有标记的字符串 * 存储在 Strings.xml 中,或者我是否必须将此字符串保留在我的 Java 文件中。
最佳答案
第 1 步:有一个 strings.xml
文件,例如:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="welcome">Welcome to <b>Android</b>!</string>
</resources>
你会注意到这是来自 the documentation that Jason Robinson linked to .
第 2 步:没有第 2 步可以从布局、 list 等中将其用作 @string/welcome
。你已经完成了。
步骤 #2b:如果您需要在 Java 中使用此值,请使用 getText()
而不是 getString()
。
关于android - 有没有办法在 strings.xml 中存储带标记的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10374847/