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


Question

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: \n-Line2\n-Line3"
   android:layout_width="54dip"
   android:layout_height="fill_parent"
   android:textSize="11px" />
1
237
5/8/2016 12:12:42 AM

Accepted Answer

Don't trust the Visual editor. Your code does work in the emu.

283
5/16/2010 4:51:25 AM

Try:

android:lines="2"

\n should work.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon