0

I need to use a different font for the bold elements in HTML text rendered in an Android textview.

I tried doing it this way, but it looks like the Typeface style argument just sets the entire textview to normal or bold, rather than setting the font for that style in the textview.

TextView tv = (TextView) dialogView.findViewById(R.id.textInstructions);
String instructions = "<b>Headline</b><br/>Regular Text";
tv.setText(Html.fromHtml(instructions));

Typeface font = Typeface.createFromAsset(BaseActivity.this.getAssets(), "OpenSans-Regular.ttf");
Typeface bold = Typeface.createFromAsset(BaseActivity.this.getAssets(), "OpenSans-Bold.ttf");
tv.setTypeface(font, Typeface.NORMAL);
tv.setTypeface(bold, Typeface.BOLD);

Looks like this stackoverflow question answers it, it requires one to merge the two true type fonts into one:

Html in text view with different fonts for bold and italic

But I haven't been able to find instructions on how to merge the fonts in ttfedit. I opened the utility but am at a loss on how to use it.

Community
  • 1
  • 1
MonkeyBonkey
  • 46,433
  • 78
  • 254
  • 460
  • use a spannable string . http://stackoverflow.com/questions/16335178/different-size-of-strings-in-the-same-textview/16335416#16335416 – Raghunandan Sep 14 '13 at 10:57
  • that would require me to programatically parse and set the text items individually, which would make it easier for me to just create seperate textviews. We are trying to use the same text view and have all the formatting info set in the instructions string (which would come from a resource file) – MonkeyBonkey Sep 14 '13 at 11:22

2 Answers2

0

Looks like this stackoverflow question answers it, it requires one to merge the two true type fonts into one:

Html in text view with different fonts for bold and italic

Community
  • 1
  • 1
MonkeyBonkey
  • 46,433
  • 78
  • 254
  • 460
0
tv.setText(Html.fromHtml("<html><body><font size=5 color=red>Hello </font> World </body><html>"));

Try this.

Kanwaljit Singh
  • 4,339
  • 2
  • 18
  • 21