androidxmlandroid-layoutnewlineandroid-resources

String Resource new line /n not possible?


It doesn't seem like it's possible to add a new line /n to an XML resource string. Is there another way of doing this?


Solution

  • 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 &lt;br /&gt; for a line break(<br />)

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