【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">

完成~

相关推荐
我是阿亮啊1 分钟前
Android Handler 机制完全解析
android·handler·handler机制
STCNXPARM8 分钟前
Android camera子系统概述
android·图像处理·摄像头·车载
牛马11118 分钟前
flutter Riverpod 中的 overrideWith
android·java·flutter
2501_9371931431 分钟前
TV 电视影视大全:全终端流畅观影技术解析
android·源码·源代码管理·机顶盒
catchadmin40 分钟前
PHP 现在可以零成本构建原生 iOS 和 Android 应用 NativePHP for Mobile v3 发布
android·ios·php
独自破碎E1 小时前
【回溯】二叉树的所有路径
android·java
安卓机器1 小时前
安卓玩机工具推荐------免root权限使用的 支持安卓4至安卓16系统的系统开源应用 推荐
android·反编译apk
summerkissyou19871 小时前
android-蓝牙-广播启动-startAdvertising和startAdvertisingSet区别
android·蓝牙
雪球Snowball1 小时前
【Android关键流程】Configuration变更时更新应用程序配置
android
h7ml1 小时前
于 CompletableFuture 的异步编排优化企业微信通知发送性能
android·windows·企业微信