涉及文件
frameworks\base\data\fonts\
1. fonts.xml
2. fallback_fonts.xm
3. fonts.mk
4. Android.mk
5. ttf字体文件
修改方法
- 修改fonts.xml,在其中对应位置添加如下代码
<familyset version="22">
<!-- first font is default -->
<!-- add start -->
<family name="hp">
<font weight="400" style="normal">Hpsimplifiedhans-light.ttf</font>
<font weight="700" style="normal">Hpsimplifiedhans-regular.ttf</font>
</family>
<!-- 不加下面这句会导致桌面英文数字字体不发生改变 -->
<alias name="sans-serif" to="hp" />
<!-- add end -->
<family name="sans-serif">
...
<!-- modify start -->
<family lang="zh-Hans">
<font weight="400" style="normal">Hpsimplifiedhans-light.ttf</font>
<font weight="700" style="normal">Hpsimplifiedhans-regular.ttf</font>
</family>
<family lang="zh-Hant">
<font weight="400" style="normal">Hpsimplifiedhans-light.ttf</font>
<font weight="700" style="normal">Hpsimplifiedhans-regular.ttf</font>
</family>
<!-- modify end -->
...
</familyset>
- 修改fallback_fonts.xml,在对应位置添加如下代码(该文件在android5.0之后不会被framework读取,但是fonts文件头部注释要求保持同步,具体可参照注释)
<familyset>
<!-- add start -->
<family>
<fileset>
<file>Hpsimplifiedhans-light.ttf</file>
<file>Hpsimplifiedhans-regular.ttf</file>
</fileset>
</family>
<!-- add end -->
...
</familyset>
# modify start
PRODUCT_COPY_FILES := \
frameworks/base/data/fonts/system_fonts.xml:$(TARGET_COPY_OUT_SYSTEM)/etc/system_fonts.xml \
frameworks/base/data/fonts/fonts.xml:$(TARGET_COPY_OUT_SYSTEM)/etc/fonts.xml \
frameworks/base/data/fonts/fallback_fonts.xml:$(TARGET_COPY_OUT_SYSTEM)/etc/fallback_fonts.xml
# modify end
ifneq ($(MULTI_LANG_ENGINE),REVERIE)
...
# modify
PRODUCT_PACKAGES := \
Hpsimplifiedhans-light.ttf \
Hpsimplifiedhans-regular.ttf \
...
ifeq ($(MINIMAL_FONT_FOOTPRINT),true)
...
else # !MINIMAL_FONT
font_src_files += \
Hpsimplifiedhans-light.ttf \
Hpsimplifiedhans-regular.ttf \
...
frameworks\base\data\fonts\
- PS:修改mk文件时,需保证前一行换行符之后没有任何字符,后一行前面的空白中没有非法字符。否则编译会报错