8

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?

3
  • possible duplicate of set font at runtime, Textview Commented Nov 30, 2010 at 14:05
  • 1
    this is not a duplicate of set font at runtime. It's a more specific case. He want's to set the font for only part of the text. This is more challenging than simply supplying a typeface from a ttf assett. Commented Oct 7, 2015 at 22:29
  • did you get the solution for this problem? Commented Feb 15, 2022 at 16:49

2 Answers 2

5

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".

Sign up to request clarification or add additional context in comments.

3 Comments

I can get this working with default fonts like monospace - but how can I use custom fonts that I have in my assets directory? I tried all the default paths to the assets directory - but no luck :(
Same issue.. Any luck?
Question is about custom font.
-4

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.