0

I'm trying to do this

The important part of that code is here:

Notice this line of code where "fontAssetName" would be some font file (in my case it's DroidSans.ttf) which has to be in my assets folder.

final Typeface regular = Typeface.createFromAsset(context.getAssets(),
            fontAssetName);

I want to do it without having to have a copy of ttf font file in my assets folder. This is because I don't want to have to deal with the copyright license of downloading a font. The font I want to use is DroidSans.ttf which should be provided in the android sdk as it is the default font. Is there any way I can access this font from the android sdk?

Community
  • 1
  • 1
Lv99Zubat
  • 853
  • 2
  • 10
  • 27

1 Answers1

-1

Android has built in fonts,

android:fontFamily="sans-serif"           // roboto regular
android:fontFamily="sans-serif-light"     // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-thin"      // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium"    // roboto medium (android 5.0)

If you want to use something different, you need to include the font yourself as you were doing.

Android doesn't include a ton of fonts like a desktop OS. The reason is that it bloats the distribution and creates a non-homogeneous look across apps.

Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134
  • I don't want to use something different. I want to use what android provides. How do I access a .ttf font file that android provides? – Lv99Zubat Apr 13 '16 at 21:50
  • You don't have to load the TTF font. Just set the font family as I showed above and you get that font. – Jeffrey Blattman Apr 14 '16 at 22:41
  • 1
    Did you take the first line in my question description into account when you wrote this answer? – Lv99Zubat Apr 19 '16 at 18:03
  • To "get the TTF that Android provides", head over to AOSP and find the TTF file. You don't get access to that through the SDK. Alternatively, you can find at least some of them at `/system/fonts` on your device. – Jeffrey Blattman Apr 19 '16 at 19:04