String Resource New Line /N Not Possible

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>

How to make a new line or tab in string XML (eclipse/android)?

Add \t for tab and \n for new line.

Line break in resources strings doesn't work

As seeming.amusing said in the comments it was the inputType the reason that line break are ignored. I just delete this line

android:inputType="textPersonName"

Now it works!

Android TextView new line isn't working

Found the issue I had to take android:inputType="textPersonName" out of the XML for the TextView. I had mistakenly left the Html.fromHtml(...) method call when I initially removed android:inputType="textPersonName". After calling message.setText("This\n Is\n A Test"); with NO android:inputType="textPersonName".Everything worked as expected.

For final clarity....

The newline character "\n" will not work if the input type is "textPersonName"

The newline character for Andriod is "\n"

Why a string from xml web service doesn't show new line in Android TextView?

after working on straight web service with no unicode decoding, I was able to read the new lines in the regex

(\\s{2})

which basically means the new lines are arriving as two spaces. Of course doing the following has fixed my problem

str.replaceAll("(\\s{2})", "\n\n");

for straight ASCII/UTF-8 text and the following for Unicode for world languages

str.replaceAll("(\\s{2])", "<br /><br />");

It's not the best solution, but has cleared my problem.



Related Topics



Leave a reply



Submit