Mulai 27 Maret 2025, sebaiknya gunakan android-latest-release
, bukan aosp-main
, untuk mem-build dan berkontribusi pada AOSP. Untuk mengetahui informasi selengkapnya, lihat Perubahan pada AOSP.
Menambahkan font kustom
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Anda kini dapat menggunakan overlay resource runtime (RRO) untuk mengubah font. Dengan menambahkan font
kustom untuk membuat paket font, Anda dapat menggunakan font dalam tema dan menggunakan RRO untuk menerapkan
penyesuaian.
Selesaikan tugas berikut:
Contoh struktur file dan file contoh disediakan di
custom-fonts.zip.
Download, lalu ekstrak file ini secara lokal untuk Anda gunakan sendiri.
Membuat paket font
Untuk membuat paket font:
- Tambahkan semua file
ttf
font ke paket font di
partisi vendor
. Contoh:
vendor/[oem]/fonts/[oem]-sans/
- Buat file
Android.mk
untuk paket font. Contoh:
vendor/[oem]/fonts/[oem]-[fontname]/Android.mk
- Pastikan modul akan diinstal di partisi
product
di
folder etc
. Untuk melakukannya, pastikan modul memiliki flag berikut:
LOCAL_MODULE_CLASS := ETC
LOCAL_PRODUCT_MODULE := true
LOCAL_MODULE_PATH := $(TARGET_OUT_PRODUCT)/fonts
Kode contoh yang diberikan di atas mengilustrasikan definisi lengkap modul paket font.
- Buat file bernama
fonts.mk
untuk paket font, lalu tambahkan file font
ttf
ke PRODUCT_PACKAGES
. Contoh:
vendor/[oem]/fonts/[oem]-[fontname]/fonts.mk
Contoh:
PRODUCT_PACKAGES := \
[font name].ttf \
Membuat paket overlay perangkat
- Buat modul bernama
fonts_customization.xml
untuk ditambahkan ke build.
Modul ini mengarah ke file fonts_customization.xml
yang berisi keluarga font
dan memanggil file make dari semua paket font. Contoh:
vendor/[oem]/[device]_overlay/fonts/Android.mk
- Buat jenis font:
vendor/[oem]/[device]_overlay/fonts/fonts_customization.xml
Tingkat root file harus berupa tag fonts-modification
. Tambahkan
jenis font untuk setiap paket font di bawah elemen ini. Selain itu, tambahkan
customizationType="new-named-family"
ke setiap jenis font, dan pastikan
setiap jenis font memiliki atribut name
. Nama ini akan digunakan nanti untuk mengakses
jenis font. File ini harus ditambahkan ke modul
fonts_customizations.xml
yang ditentukan sebelumnya di Android.mk
.
Contoh yang diberikan di atas berisi file fonts_customization.xml
yang valid.
- Buat
fonts.mk
. Contoh:
vendor/[oem]/[device]_overlay/fonts/fonts.mk
- Tambahkan
fonts_customization.xml
di bagian flag PRODUCT_PACKAGES
.
- Panggil setiap paket font yang dibuat sebelumnya.
$(call inherit-product-if-exists, vendor/[oem]/fonts/[oem]-[fontname]/fonts.mk)
- Tambahkan modul font ke build di bagian
PRODUCT_PACKAGES
, lalu build ulang.
Font akan diinstal di sistem.
- Verifikasi bahwa file font
ttf
berada di
folder /product/fonts
di perangkat.
- Pastikan
fonts_customization.xml
berada di /product/etc/
di
perangkat.
Menggunakan jenis font sistem baru
Untuk menggunakan jenis font sistem baru:
<style name="customstyle">
<item name="android:fontFamily">customfontfamily</item>
</style>
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-08-10 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-10 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```"]]