When you consider using external fonts, there are two options for the developer. He can either pack the fonts along with the app. In that case, if the fonts are already present on the phone, they will still be downloaded along with the APK. The other way is to add downloadable fonts to your Android app. The font provider application retrieves and caches the fonts so other application can request and share fonts.
What are downloadable fonts?
Downloadable fonts are directly provided to the requesting app if there are already present in the font provider This happens when some app has already requested that particular font, the font provider has retrieved it earlier and made it available to all the apps. Or if the fonts are not on phone, they are downloaded by the font provider at the time of the first launch of the app and then provided to the app via font provider (Scenario in which no app has ever requested the needed font via font provider). Currently, all the Google fonts can be used as downloadable fonts.
Advantages of using downloadable fonts
Since the downloadable fonts need not be added to the app and multiple apps can use the same fonts, here are the advantages that downloadable fonts provide.
- Reduces the APK size
- User data consumption is saved as multiple apps can share the needed fonts and they are downloaded only once
Disadvantages of using downloadable fonts
- The only disadvantage is that the first app launch can take a few seconds to download the font if the font has never been requested by any other apps and never stored and cached by font provider previously
Your machine should be running Android Studio 3.0 or above.
In your layout editor, select the TextView for which you want to use downloadable fonts and then select fontFamily attribute under the Properties tab as shown below.
Scroll down and select More Fonts option. A window opens where you can select the font you want. Make sure to check the “Create downloadable font” option and click OK.
Run the app and you can see the downloadable fonts in action.
Android Studio generates three XML files for you and also adds the meta-data in your app’s manifest file and hence makes sure that the fonts are rendered correctly in your app.
Adding custom fonts to your app becomes so easy using downloadable fonts and also it helps you keep your app size small. If you face any difficulties, feel free to discuss it in the comments section. Also, like our Facebook page and follow us on Twitter where we keep posting some other cool Android development stuff.