How do I add a newline to a TextView in Android?
When I define a TextView
in xml
, how do I add a new line to it? \n
seems not to work.
<TextView
android:id="@+id/txtTitlevalue"
android:text="Line1 -\nLine2"
android:layout_width="54dip"
android:layout_height="fill_parent"
android:textSize="11px" />
Solution 1:
Don't trust the Visual editor. Your code does work in the emu.
Solution 2:
Try:
android:lines="2"
\n
should work.
Solution 3:
try System.getProperty("line.separator");
Solution 4:
I think this has something to do with your HTM.fromHtml(subTitle)
call: a "\n" doesn't mean bupkis to HTML. Try <br/>
instead of "\n".