user3051755 user3051755 - 1 year ago 118
Android Question

Different typeface for parts of text

I have two typefaces and I would like to use Typeface1 for the titles and Typeface2 for the body.

Is there a way to do that? I can add tags around the title if that would help, like


Typeface typeface1 = Typeface.createFromAsset(getAssets(), "fonts/Typeface1.ttf");
Typeface typeface2 = Typeface.createFromAsset(getAssets(), "fonts/Typeface2.ttf");

textView.setText("<b>Title 1</b>\n" +
"Body 1\n" +
"<b>Title 2</b>\n" +
"Body 2\n" +
"<b>Title 3</b>\n" +
"Body 3");

Answer Source

You need to use Html.fromHtml() to use HTML in your XML Strings. Simply referencing a String with HTML in your layout XML will not work.



This might work

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download