Starting March 27, 2025, we recommend using android-latest-release
instead of aosp-main
to build and contribute to AOSP. For more information, see Changes to AOSP.
Add custom fonts
Stay organized with collections
Save and categorize content based on your preferences.
You can now use runtime resource overlays (RROs) to change fonts. By adding custom
fonts to make a font package, you can use fonts in themes and use RROs to apply the
customizations.
Complete these tasks:
A sample file structure and sample files are provided in
custom-fonts.zip.
Download and then extract this file locally for your own use.
Make a font package
To make a font package:
- Add all the font
ttf
files to the font package in the
vendor
partition. For example:
vendor/[oem]/fonts/[oem]-sans/
- Create the
Android.mk
file for the font package. For example:
vendor/[oem]/fonts/[oem]-[fontname]/Android.mk
- Make sure the module will be installed in the
product
partition in the
etc
folder. To do so, confirm the module has the following flags:
LOCAL_MODULE_CLASS := ETC
LOCAL_PRODUCT_MODULE := true
LOCAL_MODULE_PATH := $(TARGET_OUT_PRODUCT)/fonts
The sample code provided above illustrates a complete definition of a font package module.
- Create a file named
fonts.mk
for the font package and then add the font
ttf
files to PRODUCT_PACKAGES
. For example:
vendor/[oem]/fonts/[oem]-[fontname]/fonts.mk
For example:
PRODUCT_PACKAGES := \
[font name].ttf \
Create a device overlay package
- Make a module called
fonts_customization.xml
to be added to the build.
This module points to the fonts_customization.xml
file that contains the font
families and calls the make files of all the font packages. For example:
vendor/[oem]/[device]_overlay/fonts/Android.mk
- Create the font families:
vendor/[oem]/[device]_overlay/fonts/fonts_customization.xml
The root level of the file must be a fonts-modification
tag. Add
font families for each of the font packages under this element. In addition, add
customizationType="new-named-family"
to every font family, and make
sure each has a name
attribute. This name is used later to access the
font family. This file must be added to the fonts_customizations.xml
module defined previously in Android.mk
.
The sample provided above contains a valid fonts_customization.xml
file.
- Create
fonts.mk
. For example:
vendor/[oem]/[device]_overlay/fonts/fonts.mk
- Add
fonts_customization.xml
under the PRODUCT_PACKAGES
flag.
- Call into each of the previously created font packages.
$(call inherit-product-if-exists, vendor/[oem]/fonts/[oem]-[fontname]/fonts.mk)
- Add the font module to the build under
PRODUCT_PACKAGES
and then rebuild.
The fonts will be installed on the system.
- Verify that the
ttf
fonts files are in the
/product/fonts
folder on the device.
- Verify that
fonts_customization.xml
is in /product/etc/
on the
device.
Use the new system fonts family
To use the new system fonts family:
<style name="customstyle">
<item name="android:fontFamily">customfontfamily</item>
</style>
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-08-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-08-26 UTC."],[],[],null,["# Add custom fonts\n\nYou can now use runtime resource overlays (RROs) to change fonts. By adding custom\nfonts to make a font package, you can use fonts in themes and use RROs to apply the\ncustomizations.\n\nComplete these tasks:\n\n- [Make a font package](/docs/automotive/hmi/car_ui/fonts#make)\n- [Create a device overlay package](/docs/automotive/hmi/car_ui/fonts#create)\n- [Use the added system fonts family](/docs/automotive/hmi/car_ui/fonts#use)\n\nA sample file structure and sample files are provided in\n[custom-fonts.zip](/static/docs/automotive/hmi/car_ui/custom-fonts.zip).\nDownload and then extract this file locally for your own use.\n\nMake a font package\n-------------------\n\nTo make a font package:\n\n1. Add all the font `ttf` files to the font package in the `vendor` partition. For example:\n\n `vendor/[oem]/fonts/[oem]-sans/`\n2. Create the `Android.mk` file for the font package. For example:\n\n `vendor/[oem]/fonts/[oem]-[fontname]/Android.mk`\n3. Make sure the module will be installed in the `product` partition in the `etc` folder. To do so, confirm the module has the following flags: \n\n ```makefile\n LOCAL_MODULE_CLASS := ETC\n LOCAL_PRODUCT_MODULE := true\n LOCAL_MODULE_PATH := $(TARGET_OUT_PRODUCT)/fonts\n ```\n\n The sample code provided above illustrates a complete definition of a font package module.\n4. Create a file named `fonts.mk` for the font package and then add the font `ttf` files to `PRODUCT_PACKAGES`. For example:\n\n `vendor/[oem]/fonts/[oem]-[fontname]/fonts.mk`\n\n For example: \n\n ```objective-c\n PRODUCT_PACKAGES := \\\n [font name].ttf \\\n ```\n\nCreate a device overlay package\n-------------------------------\n\n1. Make a module called `fonts_customization.xml` to be added to the build. This module points to the `fonts_customization.xml` file that contains the font families and calls the make files of all the font packages. For example:\n\n `vendor/[oem]/[device]_overlay/fonts/Android.mk`\n2. Create the font families: `vendor/[oem]/[device]_overlay/fonts/fonts_customization.xml`\n\n The root level of the file must be a `fonts-modification` tag. Add\n font families for each of the font packages under this element. In addition, add\n `customizationType=\"new-named-family\"` to every font family, and make\n sure each has a `name` attribute. This name is used later to access the\n font family. This file must be added to the `fonts_customizations.xml`\n module defined previously in `Android.mk`.\n\n The sample provided above contains a valid `fonts_customization.xml` file.\n3. Create `fonts.mk`. For example:\n\n `vendor/[oem]/[device]_overlay/fonts/fonts.mk`\n4. Add `fonts_customization.xml` under the `PRODUCT_PACKAGES` flag.\n5. Call into each of the previously created font packages.\n `$(call inherit-product-if-exists, vendor/[oem]/fonts/[oem]-[fontname]/fonts.mk)`\n\n6. Add the font module to the build under `PRODUCT_PACKAGES` and then rebuild. The fonts will be installed on the system.\n7. Verify that the `ttf` fonts files are in the `/product/fonts` folder on the device.\n8. Verify that `fonts_customization.xml` is in `/product/etc/` on the device.\n\nUse the new system fonts family\n-------------------------------\n\nTo use the new system fonts family: \n\n```text\n\u003cstyle name=\"customstyle\"\u003e\n \u003citem name=\"android:fontFamily\"\u003ecustomfontfamily\u003c/item\u003e\n\u003c/style\u003e\n```"]]