0

I use Html.fromHtml() in my application to display bold and regular characters in the same TextView. But I have 3 different fonts for italic,bold and regular text, and I don't know how to indicate to my text view to use one or the other.

Please give me any reference or hint.
Thanks in Advance.

Sandip Armal Patil
  • 6,241
  • 21
  • 93
  • 160
Renaud Favier
  • 391
  • 6
  • 20

1 Answers1

0

if I have not misunderstood you can format a single string with different <font> tag.

For instance :

String toShow = <font: italic ...>italic string</font> <font: bold ...>bold string</font>
Html.fromHtml(toShow)

choose the tag html more appropriate for this purpose. here is a list of supporte html tag.

edit: here an example of the html font tag. As alternative I think you can use SpannableString for the same purpose.

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • yes i'm sorry i don't speak very well english and you probably have misunderstood me. I know how to display some text in bold and some other in italic or standar in the same textview. but I don't know how to set a specific font for the bold text and some other for regular one. My problem is that i have Helvetica in 8 differents .otf and not in a single .dfont. so when i set to my text view a font, it tries by itself to build the bold and italic and it does't look good at all – Renaud Favier Mar 30 '12 at 13:42
  • I think you have to go through with the SpannableString/SpanStyle pair. http://stackoverflow.com/questions/4819049/how-can-i-use-typefacespan-or-stylespan-with-custom-typeface – Blackbelt Mar 30 '12 at 13:47
  • the problem is that i'm doing that at the end of a very long project i have to change all the font and i don't want to change every textView, i'm thinking about changing the style of the application, and doing my font thing in a style.xml file – Renaud Favier Mar 30 '12 at 13:52
  • I do not understand what you need to achieve? in a single textview you want to set a string. in this string some words have a font e some other words have another font? – Blackbelt Mar 30 '12 at 13:55
  • i need all the bold text in my app to be in a specific font and all the standard text in my app to be in an other – Renaud Favier Mar 30 '12 at 14:05