阅读 170

xml中修改字体

1、右键点击 res 文件夹,然后转到 New > Android resource directory

2、在 Resource type 列表中,选择 font,然后点击 OK

image.png3、在 font 文件夹中添加字体文件

关于字体,推荐两个免费下载的网站
[谷歌](https://fonts.google.com/)
[1001freefonts](https://www.1001freefonts.com/)复制代码

image.pngps:命名必须小写字母或数字,可包含_,其他会报红。

添加之后就会生成 R.font.ma_shan_zhenng_regular 和 R.font.noto_sans_bold

4、双击字体文件可预览当前字体

image.png5、创建 font family

1)、右键点击 font 文件夹,然后转到 New > Font resource file。此时将显示 New Resource File 窗口。

2)、输入文件名,然后点击 OK。新的字体资源 Xml 会在编辑器中打开。

3)、将各个字体文件、样式和粗细属性都封装在  元素中。如下:

<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    tools:ignore="UnusedAttribute">

    <font
        android:fontStyle="normal"
        android:fontWeight="400"
        android:font="@font/ma_shan_zheng_regular"
        tools:ignore="UnusedAttribute" />

    <font
        android:fontStyle="normal"
        android:fontWeight="400"
        android:font="@font/noto_sans_bold"
         />
</font-family>复制代码

6.直接在布局 Xml 中使用 fontFamily 属性进行引用,如下图:

image.png


作者:那年匆匆
链接:https://juejin.cn/post/6976456860933029924


文章分类
后端
文章标签
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐