Skip to content Skip to sidebar Skip to footer

Android: Add Custom Fonts To System

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

Solution 1:

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.

Solution 2:

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).

  • First do the steps Nguyen explained.
  • Add following lines in fonts.xml towards the end of the <familyset> element.
<family><fontweight="400"style="normal"><custom_font>.ttf</font></family>
  • Add following lines in 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.

Solution 3:

Download Helvetica.ttf file ,copy this file into assets folder and use this code.

Typefacefont= Typeface.createFromAsset(getAssets(), "Helvetica.ttf");

    your_textview_id.setTypeface(font);

Post a Comment for "Android: Add Custom Fonts To System"