Using Html.fromHtml to set a custom font

I found this list of HTML tags that are (supposedly) supported for HTML.fromHtml to create Spanned-Text:

http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html

Is there ANY way to set a custom font using Font-Tag?

+7
android string-formatting
source share
3 answers

Outdated. See other answers.


No, there is no way to do this. You can take a look at the implementation of Html . As you will see, the font tag only supports size and color .

-3
source share

Just use the <font> with the face attribute. This was possible since at least Android 1.5 ( see Source Code ).

The value of the face attribute will be passed to the TypefaceSpan(String) constructor to create a Spannable. For example, use "monospace", "serif" or "sans-serif".

+6
source share

it worked for me

 Typeface typeface = Typeface.createFromAsset(context.getAssets(), "fonts/OpenSans-Regular.ttf"); currentRounds.setTypeface(typeface); currentRounds.setText(Html.fromHtml("Current Rounds <br><b>2650</b>")); 
0
source share

All Articles