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


当前回答

我试过了 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

其他回答

这是一个老问题,但我发现当你创建一个这样的字符串时:

<string name="newline_test">My
New line test</string>

在你的应用程序中的输出将是这样的(没有换行)

My New line test

当你把字符串放在引号里

<string name="newline_test">"My
New line test"</string>

换行符将出现:

My 
New line test

我只是面对这个问题。 不能在约束参数的TextView上工作。添加android:lines="2"似乎可以解决这个问题。

我试过了 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预览窗口的新行上显示,它也会在下一行中显示。

我知道这是一个很老的问题,但当我搜索时,它位居榜首。所以我想用另一种方法进行更新。

在strings.xml文件中,你可以输入\n或者简单地按enter键:

<string name="你的字符串名称" >这是你的字符串。 这是弦的第二行。\n\n字符串的第三行

这将导致以下在你的TextView:

这是你的绳子。 这是弦的第二行。 你的绳子的第三行。

这是因为在字符串的开始声明和新行之间有两个返回值。为了清晰起见,我还添加了\n,因为两者都可以使用。我喜欢在xml中使用回车,以便能够看到列表或任何多行字符串。我的意见。