2

Im working on my first Android application bigger than one activity.

I've read this:

Android 4.1 adds several more variants of the Roboto font style for a total of 10 variants, and they're all usable by apps. Your apps now have access to the full set of both light and condensed variants.

(here: link)

I also read somewhere, that I can use custom TTF font.

Does it mean, that Android API below 4.1 (API 16) cannot support custom fonts?

Do I have to work on API 16 or above? I have 4.0.4 phone for now, I don't want to throw it away yet...

Kamil
  • 13,363
  • 24
  • 88
  • 183

1 Answers1

4

Don't throw away your phone! You certainly can use custom fonts below API level 16.

First add your font (ttf file) to your /assets folder, then do something like:

Typeface typeface  = Typeface.createFromAsset(getAssets(), "myfont.ttf");
myTextView.setTypeface(typeface);

http://developer.android.com/reference/android/widget/TextView.html#setTypeface(android.graphics.Typeface)

It has been around since API level 1.

The fonts in your question can be used without having to include any font file - they are not "custom" but built into the platform and available for all to use.

Ken Wolf
  • 23,133
  • 6
  • 63
  • 84
  • Well, it's a bit painful to do that for all TextView and other objects. I guess there is no way to apply font to whole activity... I am right? Im worried about activity initialization performance impact when I do some for loop that does that for all objects. – Kamil Oct 01 '14 at 17:28
  • 1
    You could try this way: http://stackoverflow.com/questions/2711858/is-it-possible-to-set-font-for-entire-application/16883281#16883281 I have done it the above way and it was not too painful. Just reuse your Typeface object. – Ken Wolf Oct 01 '14 at 17:36