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.
XML does not require a specific form of line break, so you can use whatever is convenient (carriage return, linefeed, or a combination) when creating an XML file. XML parsers will do the right thing largely because they're parsing on tags, not records - so whatever line break you're using is just whitespace to XML.
Add \t
for tab and \n
for new line.
Use \n
for a line break and \t
if you want to insert a tab.
You can also use some XML tags for basic formatting: <b>
for bold text, <i>
for italics, and <u>
for underlined text
More info:
https://developer.android.com/guide/topics/resources/string-resource.html
\n didn't work for me. So I used <br/>
HTML tag
<string name="message_register_success">
Sign up is complete. <br/>
Enjoy a new shopping life at fatherofapps.com!!
</string>
Use \t to add tab and \n for new line, here is a simple example below.
<string name="list_with_tab_tag">\tbanana\torange\tblueberry\tmango</string>
<string name="sentence_with_new_line_tag">This is the first sentence\nThis is the second scentence\nThis is the third sentence</string>
add this line at the top of string.xml
<?xml version="1.0" encoding="utf-8"?>
and use
'\n'
from where you want to break your line.
ex. <string> Hello world. \n its awesome. <string>
Output:
Hello world.
its awesome.
You can use \n
for new line and \t
for tabs. Also, extra spaces/tabs are just copied the way you write them in Strings.xml
so just give a couple of spaces where ever you want them.
A better way to reach this would probably be using padding/margin in your view xml and splitting up your long text in different strings in your string.xml
\n
doesn't seem to work for tools:text
You can use <br/>
to get a preview including line breaks, but it won't show up on the device unless you format the text using something like Html.fromHtml()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With