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
How to Avoid Keyboard Pushing Layout Up on Android React-Native
How to Remove Focus from Edittext When User Is Done Editing
Android Push Notifications Not Being Received When App Closed
Android Gradle Error When Sync Style Attribute Not Found
How Capture/Log API Calls (Function Calls) Made by Android App
How to Change Firebase Project Directory
How to Refresh the Fragment After Activity Finished in Android
Getting the Current Fragment Instance in the Viewpager
Sharing Link on Whatsapp from Mobile Website (Not Application) For Android
Activity Restart on Rotation Android
Android How to Get Current Positon on Recyclerview That User Scrolled to Item
Android No on Screen Keybord ( Only Voice )
Pdf Not Open in Webview from Url
Move to Another Edittext When Soft Keyboard Next Is Clicked on Android
How to Change Listview Height Dynamically in Android
Retrofit Body Giving Null Values But Coming Perfect in Postman
How Remove Unnecessary Space Between Cards in Recyclerview
How to Automatically Open App When Receive Push Notification