Android - 字符串的 XML 语法

发布于 2024-09-26 09:04:47 字数 533 浏览 1 评论 0原文

在我的 XML 值字符串代码中,我有一个包含一些文本的字符串,我只想其中的几个单词是彩色的。我还想为某些文本换行。

我可以做这样的事情:< b>我的粗体文字< /b>这很有效(为这篇文章添加了前导空间)。

我尝试用颜色标记文本,但没有显示颜色,也没有错误。

name="dogs"
    >Red Dog, <color foreground="#FFFF0000"> Sammy</color></string>

我还尝试添加新行 - 我尝试过以下操作:
< LF>一些文字,开头的空格仅适用于这篇文章< /LF>
< CR>这也不起作用< /CR>
< p>一些文字,开头的空格仅适用于这篇文章< p>

但是,没有新段落/新行、回车 rtn 发生。

我做错了什么?或者,更正确地说,我该如何实现这一目标?
谢谢

In my XML values strings code, I have a string with some text that I want to have only a few of the words in color. I also want to have a new line for some of the text.

I can do things like: < b> my bold text < /b> and that works (leading space added for this post).

I try to tag the text with color but no color shows up and there are no errors.

name="dogs"
    >Red Dog, <color foreground="#FFFF0000"> Sammy</color></string>

I also try adding a new line - I've tried things like:
< LF> some text, space at beginning only for this post < /LF>
< CR> this didn't work either < /CR>
< p> some text, space at beginning only for this post < p>

But, no new paragraph / new line, carriage rtn happens.

What am I doing wrong? Or, more correctly put, How do I accomplish this?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲影 2024-10-03 09:04:47

根据 文档,三个受支持的 HTML 标记用于值strings.xml 是(没有 fromHTML()):

<b>
<i>
<u>

至于新行,您可以尝试使用裸的 \n。我记得至少有一个人报告说它有效。

As per the documentation, the three supported HTML tags for values in the strings.xml are (without fromHTML()):

<b>
<i>
<u>

As for a new line, you could try a bare \n. I remember at least one folk reporting it worked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文