问题
I found this list of HTML-Tags that are (supposedly) supported for HTML.fromHtml to create a Spanned-Text:
http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html
Now is there ANY way to set a custom Typeface with the Font-Tag?
回答1:
Outdated. See other answers.
No, there's no way to do so. You can take a look at the Html implementation. As you will see, the font
tag supports size
and color
only.
回答2:
Simply use a <font>
tag with a face
attribute. This has been 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 the Spannable. For example, use "monospace", "serif", or "sans-serif".
回答3:
this has 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>"));
来源:https://stackoverflow.com/questions/4314507/using-html-fromhtml-to-set-custom-typeface