Tag Archives: TextView

Using HTML format in TextView

In Android, HTML formatting is possible by using Html.fromHtml() in TextView.

TextView tv = (TextView)findViewById(R.id.text);
tv.setText(Html.fromHtml("Text with <br><font color=\'#ff0000\'>Color</font> and <b>Bold</b>"));

To use a string from a resource, the string have to be formatted this way:

[strings.xml]

<string name="html_string">Text with &lt;br&gt;&lt;font color=\'#898f97\'&gt;Color&lt;/font&gt; and &lt;b&gt;Bold&lt;/b&gt;</string>

[TestActivity.java]

TextView tv = (TextView)findViewById(R.id.text);
tv.setText(Html.fromHtml(getResources().getString(R.string.html_string)));