How to set text inside TextView in two lines?

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

+6
source share
4 answers

Enter \n for a new line

 This will be\ntwo lines 

will look like

 This will be two lines 

Also, make sure TextViews setsingleline() not set to true.

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

You can use \n to insert a line break in a text view.

Like this:

 playing.setText( "STATION: \n" + stations.get( position ) ); 
+4
source

Make sure your TextView has a couple lines of code in xml:

android:lines="2" android:singleLine="false"

By default, android:singleLine true. Thus, you can install it in XML or in Java code ie:

 txtNextLine.setSingleLine(false); txtNotActivate.setText("first line\n"+"second line"); 

Hope this helps.

0
source

Source: https://habr.com/ru/post/899441/


All Articles