Reputation: 26548
I know how to use custom font in an app, but what I want to do is adding custom fonts system-wide, just like adding a new font on Windows. If there's no official way, which module of android source code should I read? I have to change android source code and build it to support custom fonts.
Upvotes: 6
Views: 8341
Reputation: 2123
Here are steps to add custom font into Android build-in system:
Copy custom font .ttf into frameworks/base/data/fonts
Modify frameworks/base/data/fonts/Android.mk
Add your custom font into list of 'font_src_files'
font_src_files :=
Roboto-Regular.ttf
....
AndroidClock_Solid.ttf
<custom_font>.ttf \
Modify frameworks/base/data/fonts/fonts.mk
Add your custom font into list of PRODUCT_PACKAGES
PRODUCT_PACKAGES :=
DroidSansFallback.ttf
...
AndroidClock_Solid.ttf
<custom_font>.ttf \
Rebuild
NOTE: Check if your custom font exists in out/target/product/generic/system/fonts or not. If yes, your custom font have already included in system. If no, recheck your modification.
Upvotes: 11
Reputation: 142
I'm working on Android 5.1.1 Lollipop.
Nguyen's answer supported me, but only to some extent. So I have to edit fonts.xml
and fallback_fonts.xml
files (as commented by Chef Pharaoh).
fonts.xml
towards the end of the <familyset>
element.<family>
<font weight="400" style="normal"><custom_font>.ttf</font>
</family>
fallback_fonts.xml
towards the end of the <familyset>
element.<family>
<fileset>
<file><custom_font>.ttf</file>
</fileset>
</family>
(replace <custom_font>
with your custom font name)
I found this link a bit helpful, and it is in Chinese.
FYR following note is about the file fallback_fonts.xml
NOTE: this file is the legacy format, for compatibility with apps. The new, more flexible format is fonts.xml. Please keep the two in sync until the legacy format can be fully removed.
Upvotes: 2
Reputation: 1603
Download Helvetica.ttf file ,copy this file into assets folder and use this code.
Typeface font = Typeface.createFromAsset(getAssets(), "Helvetica.ttf");
your_textview_id.setTypeface(font);
Upvotes: 1