Damir
Damir

Reputation: 56199

How to set text inside TextView to be in two lines?

Is there any way to programmatically set text in TextView to be in two lines ?

Upvotes: 10

Views: 25825

Answers (4)

umi
umi

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

drewi
drewi

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

Nicholas Magnussen
Nicholas Magnussen

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

MKJParekh
MKJParekh

Reputation: 34301

TextView tv = new TextView(this);
tv.setText("First Line \n this is Second Line");
setContentView(tv);

Upvotes: 9

Related Questions