Image credit:Google Play Services (on devices with version 11+) is one such font provider, which I used for Lato as it is a. There isn’t documentation yet on how to implement your own font provider if you were to use a custom font not available through Google Play Services, however you can use fonts in XML which is still an improvement over what it used to be!As you can see in the image above, apps using Downloadable Fonts make a using the API which retrieves the from the Font Provider. The Font Provider does not need to download fonts if it already exists in the Font cache.Developers don’t need to use these APIs directly if using Downloadable Fonts through XML, which is described more in the next section.Advantages of using Downloadable Fonts:. Reduced APK size — which can significantly!.
Since the apps can share fonts from the same provider, this results in less usage of precious memory, disk space and cellular data. Can you guess how many Roboto font files are in your phone’s storage right now? 🙀 (yes there are apps that have them in their APKs).Great, let’s get started!There are three ways of implementing Downloadable Fonts in your app — using Android Studio & Google Play services, programmatically or via the Support Library. I used Android Studio to generate the required files, and used the Fonts in XML feature from the Support library to apply the downloaded fonts.I decided to do it via XML because then you can declare the required fonts in your app’s manifest file, which allows the framework to download them ahead of time. If doing it programmatically, you can only request for fonts after the app is launched, which can cause a delay in the first layout time. Also, it is less work do it via XML!1.
If you want to use Android Studio to generate the required files, then you’ll need version 3.0+. Add the following (version 26+) to your module’s build.gradle: implementation 'com.android.support:support-compat:27.0.2'2. Select a text view in your app that you want to apply the font to and click on the fontFamily attribute under Attributes in the graphical layout.