admin管理员组

文章数量:1614277

一、准备字体

当然第一步也是最重要的第一步就是需要准备一个字体,可以自己在网站搜索免费字体下载

这里提供一个免费下载字体的网站,只用于学习使用,切勿商用!!!

字体天下

二、替换字体

字体相关的文件路径:frameworks/base/data/fonts

  1. 将网上下载的字体复制到这个路径下,这里假设我添加的字体文件名称为:ErvinFonts.ttf

  1. 将字体文件添加到fonts.mk

  2. Android.bp文件中添加ErvinFonts.ttf

  1. 修改fonts.xml中的内容,将下列所有的Roboto-Regular.ttf替换为ErvinFonts.ttf即可

  2. <familyset version="23">
        <!-- first font is default -->
        <family name="sans-serif">
            <font weight="100" style="normal">Roboto-Regular.ttf
              <axis tag="ital" stylevalue="0" />
              <axis tag="wdth" stylevalue="100" />
              <axis tag="wght" stylevalue="100" />
            </font>
            <font weight="200" style="normal">Roboto-Regular.ttf
              <axis tag="ital" stylevalue="0" />
              <axis tag="wdth" stylevalue="100" />
              <axis tag="wght" stylevalue="200" />
            </font>
            <font weight="300" style="normal">Roboto-Regular.ttf
              <axis tag="ital" stylevalue="0" />
              <axis tag="wdth" stylevalue="100" />
              <axis tag="wght" stylevalue="300" />
            </font>
            <font weight="400" style="normal">Roboto-Regular.ttf
              <axis tag="ital" stylevalue="0" />
              <axis tag="wdth" stylevalue="100" />
              <axis tag="wght" stylevalue="400" />
            </font>
            <font weight="500" style="normal">Roboto-Regular.ttf
              <axis tag="ital" stylevalue="0" />
              <axis tag="wdth" stylevalue="100" />
              <axis tag="wght" stylevalue="500" />
            </font>
            <font weight="600" style="normal">Roboto-Regular.ttf
              <axis tag="ital" stylevalue="0" />
              <axis tag="wdth" stylevalue="100" />
              <axis tag="wght" stylevalue="600" />
            </font>
            <font weight="700" style="normal">Roboto-Regular.ttf
              <axis tag="ital" stylevalue="0" />
              <axis tag="wdth" stylevalue="100" />
              <axis tag="wght" stylevalue="700" />
            </font>
            <font weight="800" style="normal">Roboto-Regular.ttf
              <axis tag="ital" stylevalue="0" />
              <axis tag="wdth" stylevalue="100" />
              <axis tag="wght" stylevalue="800" />
            </font>
            <font weight="900" style="normal">Roboto-Regular.ttf
              <axis tag="ital" stylevalue="0" />
              <axis tag="wdth" stylevalue="100" />
              <axis tag="wght" stylevalue="900" />
            </font>
    
  3. 编译验证
    frameworks/base/data/fonts路径下执行mm命令即可,会在out\target\product\XXX\system路径下生成etc文件夹和font文件夹,push到对应路径下重启机器就可以验证啦~

三、最后

关于fonts.xml文件的作用可以查看此文章,相信看完这篇文章会让你对系统字体了解更加深入 Android fonts相关知识以及fonts.xml解读

本文标签: 字体系统