在XML资源字符串中添加新的行/n似乎是不可能的。还有别的办法吗?


当前回答

我想进一步解释这个问题。 他们的意思是这个图标:

它打开了一个“真正的编辑器窗口”,而不是大概览中的有限功能文本框。在该编辑器窗口中,允许特殊字符、换行符等,并在保存时转换为正确的xml“代码”

其他回答

我试过了 1-顶部单词\n底部单词 2顶部单词ENTER底部单词

没有工作 最后<br/>为我在android studio工作

事实上,正确的使用方法是\n,尽管在构建应用程序之后可能会看到它完成。只对设计有影响,对应用没有影响

<string name="available_balance">Available\nBalance</string> //Look good on the app and Available\nBalance in android studio
<string name="available_balance">Available<br/>Balance</string> //Look good in android studio and Available Balance on the App
\n tag worked in the strings.xml file

Eg:

 <string name="hello">Hello World &amp;\nWelcome</string>

输出:

Hello World &
Welcome

注意:

请确保您没有在\n的前后添加空格。” 当你运行应用程序时,即使它不在UI预览窗口的新行上显示,它也会在下一行中显示。

在最新版本的Android studio中,"\n"会像它应该在那里一样被打印出来除非整个字符串是撇号

例如:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="title">"Hello\nWorld!"</string>
</resources>

我尝试了两种选择,都是有效和简单的。

我使用了<br/> HTML标签

<string name="name_detail">
        Hey user. <br/>
        Enjoy a new shopping deal.!!
</string>

在strings.xml的顶部添加编码行

<?xml version="1.0" encoding="utf-8"?>

然后用“\n”换行 例子

<string name="name_detail">
        Hey user.\n
        Enjoy a new shopping deal.!!
</string>

很简单,你只要把 \ n 在字符串资源中任何你想要断行的地方。

例如

字符串资源有n个换行符;