Android TextView HTML text break at the end of line

363 Views Asked by At

In my text view, I am setting the HTML text:

mTextView.setText(Html.fromHtml("THIS USEFUL INTERESTING HTML TEXT IS DISPLAYED IN ANDROID TEXT VIEW"));

The Text is displayed as below: enter image description here

The long word at the end is breaking with a hyphen. I want the complete word to go into the next line instead. How can I achieve this? I need to use HTML text only. The text can be dynamic and has to scale across various display size and orientations, I cannot put newline char in the text.

2

There are 2 best solutions below

1
isaaaaame On

I'd suggest you to use attribute android:ellipsize to prevent breaking up a word

1
DaveAAA On

Try this...it should work

mTextView.setText(Html.fromHtml("THIS USEFUL" +"<br/>"+ "INTERESTING HTML TEXT IS DISPLAYED IN ANDROID TEXT VIEW"));

How to have HTML New Line Feature in Android Text View? for more clarity