Denis Steinman
Denis Steinman

Reputation: 7799

Cannot understand how to add new line only in xml

Please, explain me how can I add a new line in xml only (when I will use this string in program this must be single line)?

For example:

<string name="test">This
is
test
line</string>

But in program when I will use getString(R.string.test); it will load single string without some new line characters: This is test line.
I need this only for file formatting.

Upvotes: 0

Views: 278

Answers (1)

Morrison Chang
Morrison Chang

Reputation: 12121

If you want to force a newline in the XML string just use '\n' (assuming your TextView is sized properly):

<string>This\nis\ntest\nline</string>

Output

This
is
test
line

See: How to insert a new line in strings in Android

Otherwise you can inject in a blank space &#032; or &#160; for adjusting your string formatting.

See: How to put space character into a string name in XML?

Upvotes: 1

Related Questions