【Android】字体设置

需求 :

  1. 全局字体设置 2. 局部字体设置
    既可通过kotlin或者第三方库实现, 也可以android ui上直接实现
    此处讲的是使用Android自带的字体设置

实现 :

1. 字体文件放到src/main/res/font 目录下

2. 局部字体使用 ↓

xml 复制代码
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2.3"
                android:text="Name"
                android:textColor="@color/progress_secondary_color"
                android:textSize="15sp"
                android:fontFamily="@font/gilroy_medium_2"
                />

3. 全局字体使用

3.1 main/res/values/styles.xml 定义全局字体

xml 复制代码
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="android:fontFamily">@font/your_custom_font</item>
</style>

3.2 AndroidManifest.xml 引用style

xml 复制代码
    <application
        android:name=".TestApplication"
        android:allowBackup="true"
        android:appComponentFactory="@string/app_name"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="GoogleAppIndexingWarning"
        tools:replace="android:appComponentFactory">

完成~

相关推荐
百***266318 分钟前
使用 Logback 的最佳实践:`logback.xml` 与 `logback-spring.xml` 的区别与用法
xml·spring·logback
864记忆1 小时前
Qt 对 JSON和XML文件的操作详解
xml·qt·json
早上好啊! 树哥2 小时前
安卓开发:清除缓存并重启,删除指定路径下的文件缓存
android·缓存
h***34632 小时前
Nginx 缓存清理
android·前端·后端
Tom4i3 小时前
Perfetto 快速上手
android·性能优化·perfetto
fatiaozhang95274 小时前
创维桌面云终端-创维LB2002-黑盒-国科gk6323-2+8G-短接强刷固件包
android·电视盒子·刷机固件·机顶盒刷机·创维lb2002·创维lb2002-黑盒·创维lb2002-白盒
a***97684 小时前
使用 Logback 的最佳实践:`logback.xml` 与 `logback-spring.xml` 的区别与用法
xml·spring·logback
q***718510 小时前
MySQL--》如何在MySQL中打造高效优化索引
android·mysql·adb
IT痴者11 小时前
《PerfettoSQL 的通用查询模板》---Android-trace
android·开发语言·python
游戏开发爱好者812 小时前
iOS IPA 上传工具全面解析,从 Transporter 到开心上架(Appuploader)命令行的高效上架实践
android·ios·小程序·https·uni-app·iphone·webview