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

完成~

相关推荐
Mr.pyZhang4 小时前
Android构建系统 - 04 编译产物
android·linux
守城小轩10 小时前
Brave 132 编译指南 Android 篇 - 编译准备:系统要求与推荐工具 (三)
android·chrome·chrome devtools·指纹浏览器·浏览器开发·brave
m0_7482384210 小时前
MySQL Workbench菜单汉化为中文
android·数据库·mysql
程序员江同学11 小时前
Kotlin 技术月报 | 2025 年 2 月
android·kotlin
甜于酸12 小时前
MuMu模拟器Pro for Mac 安卓手机平板模拟器
android·macos·智能手机
best_virtuoso13 小时前
XML DOM4J 三、XPath
xml
顾林海15 小时前
深入解析 Android Activity 生命周期
android
XuanRanDev17 小时前
【构建工具】Gradle Kotlin DSL中的大小写陷阱:BuildConfigField
android·开发语言·kotlin
步、步、为营18 小时前
解锁C# XML编程:从新手到实战高手的蜕变之路
xml·数据库·c#
Nathan2024061619 小时前
Room - 基本使用及使用问题
android·面试·android jetpack