Using Html.fromHtml to set custom Typeface

不想你离开。 提交于 2019-12-06 00:49:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!