涉及文件
frameworks\base\data\fonts\
1. fonts.xml
2. fallback_fonts.xm
3. fonts.mk
4. Android.mk
5. ttf字體文件
修改方法
- 修改fonts.xml东抹,在其中對(duì)應(yīng)位置添加如下代碼
<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>
<!-- 不加下面這句會(huì)導(dǎo)致桌面英文數(shù)字字體不發(fā)生改變 -->
<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,在對(duì)應(yīng)位置添加如下代碼(該文件在android5.0之后不會(huì)被framework讀取,但是fonts文件頭部注釋要求保持同步,具體可參照注釋)
<familyset>
<!-- add start -->
<family>
<fileset>
<file>Hpsimplifiedhans-light.ttf</file>
<file>Hpsimplifiedhans-regular.ttf</file>
</fileset>
</family>
<!-- add end -->
...
</familyset>
- 修改fonts.mk,在對(duì)應(yīng)位置添加如下代碼
# 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 \
...
- 修改Android.mk 在對(duì)應(yīng)位置添加如下代碼
ifeq ($(MINIMAL_FONT_FOOTPRINT),true)
...
else # !MINIMAL_FONT
font_src_files += \
Hpsimplifiedhans-light.ttf \
Hpsimplifiedhans-regular.ttf \
...
frameworks\base\data\fonts\
- PS:修改mk文件時(shí)挠说,需保證前一行換行符之后沒有任何字符科展,后一行前面的空白中沒有非法字符低缩。否則編譯會(huì)報(bào)錯(cuò)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者