7

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.

3 Answers 3

11

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Great answer. Don't forget to edit the xml files as required.
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> <font weight="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.

Comments

1

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

2 Comments

where to download Helvetica.ttf? I'm using this way, but crashed.
check this link for downloading Helvetica.ttf file 4shared.com/get/iz-q8io5/helvetica.html

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.