Reputation: 56199
Is there any way to programmatically set text in TextView
to be in two lines ?
Upvotes: 10
Views: 25825
Reputation: 157
Make sure your TextView has couple of lines of code in xml:
android:lines="2"
android:singleLine="false"
by default android:singleLine
is true. So you can set it in XML or in Java code i.e. :
txtNextLine.setSingleLine(false);
txtNotActivate.setText("first line\n"+"second line");
Hope this will help.
Upvotes: 1
Reputation: 689
Type \n
for a new line
This will be\ntwo lines
will look like
This will be
two lines
Also, be sure that the TextViews setsingleline()
isn't set to true
Upvotes: 21
Reputation: 769
You can use \n
to insert a line break in your textview.
Like this:
playing.setText( "STATION: \n" + stations.get( position ) );
Upvotes: 4
Reputation: 34301
TextView tv = new TextView(this);
tv.setText("First Line \n this is Second Line");
setContentView(tv);
Upvotes: 9