简体   繁体   中英

How to add a long text with many paragraphs in string.xml in android

When I added many paragraphs between

<string name="bbb"> ...... </string>

it showed me following error.

[2014-12-22 14:54:55 - Inspiration] Her father rescued her from the heartless husband  and she was back her to the 
[2014-12-22 14:54:55 - Inspiration] G:\adt-bundle-windows-x86_64-20140702\workspace\Inspiration\res\layout\activity_women.xml:11: error: Error: No resource found that matches the given name (at 'text' with value '@string/Women1').

Try this

 <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.

You can add the long string to /res/values/strings.xml, as it appears you've done.

You can separate paragraphs with the \\n .

You will need to use Unicode codes for special characters like backslash, etc.. See this answer .

Yes, was just going to add what's in the other answer: The other trick is to use the CDATA trick:

<![CDATA[Foo Bar <a href="foo?id=%s">baz</a> is cool]]>

See this answer for more on that .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM