Android O feature spotlight: Developer Preview 2 adds a Bluetooth AVRCP version selector
Android O feature spotlight: Google explains the new actionable battery menu
Android O feature spotlight: Downloadable fonts will make APKs smaller, and fonts can now be XML resources
Android O feature spotlight: Apps can finally capture the mouse pointer
Android O feature spotlight: VolumeShaper lets audio apps perform cross fades, fade-outs, and more
- View All 80 Articles In This Series
Google has definitely been focusing on space-saving and performance improvements with Android O, such as faster boot times and the leaner Android Go operating system. Fonts aren't quite as exciting, unless you like to spice up your reports and presentations with obscure typefaces. Regardless, Android O has a few improvements in store for developers wanting to use custom fonts in their applications.
Downloadable Fonts API
First up is the new Downloadable Fonts API. Currently, when applications want to use fonts not included in the Android operating system, they have to include the font files in the APK. Makes sense, right? Well, there are a few problems with this approach, the main one being file sizes. You could have several applications all using the same custom font, essentially wasting space on your phone or tablet with duplicate font files.
Using this new API, apps can 'request' fonts from a supported font provider. Google Play Services is the first font provider that applications can use. Hooking into Play Services' font provider will give developers access to the massive Google Fonts library.
Requested fonts are then cached locally on the device, and shared between any app requesting them. For example, if you use four apps that need Comic Sans, only one copy of Comic Sans is actually stored on your device.
This new API is part of Android O, but applications can use Support Library 26 to use it on API versions 14 or higher (Android 4.0+).
Fonts in XML
Another improvement to font management in Android O is that fonts can be used as XML resources. Developers will be able to add fonts directly to the res/font/ folder in the project folder, and in doing so, the fonts become automatically available in Android Studio.
Previously, using custom fonts in Android apps was a bit of a pain, requiring the use of a Custom Text View or data binding. Now, fonts and font families can be created as an XML resource, and applications can even access font families as a single unit.
As you might expect, this works hand-in-hand with the Downloadable Fonts API. While fonts in XML is part of Android O, it will also work on devices running Android API 14 or higher (Android 4.0+) with Support Library 26.
You can find more information about both APIs, as well as code examples and guides, at the source links below.