How to use custom font as resource in Android
Issue #380
Downloadable fonts
https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts
Android 8.0 (API level 26) and Android Support Library 26 introduce support for APIs to request fonts from a provider application instead of bundling files into the APK or letting the APK download fonts. The feature is available on devices running Android API versions 14 and higher through the Support Library 26
Before
- Select
File -> New -> Folder -> Assets Folder
to createsrc/main/assets/fonts
1 | al myTypeface = Typeface.createFromAsset(assets, "fonts/myFont.ttf") |
In res
Create font directory
Right click res -> New -> Android Resource Directory
, select font
and name the folder font
Add custom fonts to res/font
folder. Note that name must be lower case and underscore, like opensans_extrabolditalic.ttf
Right click res/font -> New -> Font resource file
to create font family
opensans.xml
1 |
|