Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make EditText accept and display HTML formatted text

Does any one know how to make an EditText control shows html formatted text, and even writes HTML formatted text, to act like an HTML Edit Box,

like image 247
Hassan Mokdad Avatar asked Jun 09 '11 06:06

Hassan Mokdad


3 Answers

To show HTML code in an EditText you need to convert it to Spanned using Html.fromHtml(). Only a small HTML tag subset can be used in this method. You can set a Spanned as a text of an EditText. Then you can edit it and convert it back using Html.toHtml().

like image 192
Michael Avatar answered Sep 29 '22 23:09

Michael


Try using Html.fromHtml(text) to display HTML formatted text in EditText.

But Html class can recognize only few tags, its not comprehensive. You can check this blog to check which all tags are supported as of now.

like image 45
sat Avatar answered Sep 30 '22 00:09

sat


String xyz="this <br>is<br> my<br> testing <br>string ";
 String formattedString =Html.fromHtml(xyz);
like image 45
Ashish Saini Avatar answered Sep 30 '22 01:09

Ashish Saini