Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add newlines to a text resource in Android?

I have a custom Dialog that contains only a TextView to display some text in my application. The documentation lists that only the b, i, u, tt, big, small, sup, sub, and strike tags are supported. I really need to add some newlines for readability. Do I need to change to a more complicated layout, or is there some way to encode newlines in the resource? I tried adding br tags, but that did not help.

like image 843
shmuelp Avatar asked Mar 24 '10 01:03

shmuelp


People also ask

How do I add a newline to a TextView in Android?

Add Line Breaks to a TextView Just add a \n to your text. This can be done directly in your layout file, or in a string resource and will cleanly break the text in your TextView to the next line.

How do I add a new line to an XML string?

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

How do I add a new line?

To add spacing between lines or paragraphs of text in a cell, use a keyboard shortcut to add a new line. Click the location where you want to break the line. Press ALT+ENTER to insert the line break.

How do I change the line in text view?

we can add a simple '\n' to TextView text where we want to start a new line. in this way we can create a multiline TextView widget in android app. we can assign android:text attribute value by this way android:text="Line1 \n Line2 \n Line3" for a TextView widget.


1 Answers

On a lark, I tried adding \n to my resource, and happily discovered that it added a newline! I hope this saves someone else the trouble.

like image 123
shmuelp Avatar answered Oct 20 '22 08:10

shmuelp