String Resource new line /n not possible? String Resource new line /n not possible? xml xml

String Resource new line /n not possible?


use a blackslash not a forwardslash. \n

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

Also, if you plan on using the string as HTML, you can use <br /> for a line break(<br />)

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


I know this is pretty old question but it topped the list when I searched. So I wanted to update with another method.

In the strings.xml file you can do the \n or you can simply press enter:

<string name="Your string name" > This is your string.   This is the second line of your string.\n\n Third line of your string.</string>

This will result in the following on your TextView:

This is your string.

This is the second line of your string.

Third line of your string.

This is because there were two returns between the beginning declaration of the string and the new line. I also added the \n to it for clarity, as either can be used. I like to use the carriage returns in the xml to be able to see a list or whatever multiline string I have. My two cents.


After I tried next solution

  • add \n
  • add \n without spaces after it
  • use "" and press Enter inside text
  • text with press Enter
  • use lines=2

What solves me is br tag

<string name="successfullyfeatured">successfully<br/> You are now a member</string>

Update

the most reliable solution is to use Translation editor and edit text and it will handle new lines for you