How to add a line break in an Android TextView?

dropsOfJupiter picture dropsOfJupiter · Mar 21, 2011 · Viewed 310.2k times · Source

I am trying to add a line break in the TextView.

I tried suggested \n but that does nothing. Here is how I set my texts.

TextView txtSubTitle = (TextView)findViewById(r.id.txtSubTitle);
txtSubTitle.setText(Html.fromHtml(getResources().getString(R.string.sample_string)));

This is my String: <string name="sample_string">some test line 1 \n some test line 2</string>

It should show like so:

some test line 1
some test line 2

But it shows like so: some test line 1 some test line 2.

Am I missing something?

Answer

RonN picture RonN · Aug 20, 2011

\n works for me, like this:

<TextView android:text="First line\nNext line"