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

完成~

相关推荐
91刘仁德6 小时前
MYSQL 事务原理及使用
android·mysql·adb
一笑的小酒馆7 小时前
AndroidKMP之瀑布流实现
android
RainyJiang8 小时前
AI时代下,Android的边界正在消失
android·openai·ai编程
Android-Flutter8 小时前
android 内存抖动详解
android
方白羽10 小时前
为什么 Android 非要用 Intent 传值?
android·ios·harmonyos
方白羽12 小时前
Android17 重写 MessageQueue,解决 Handler 隐性卡顿
android·app
蜡台13 小时前
Kotlin 零基础完整版实战教程|从语法入门到Android工程实战
android·开发语言·kotlin
律宏阔13 小时前
Android 车载 USB 开发笔记:USB Host、USB 串口、USB-CAN、HID 与系统 API
android
律宏阔13 小时前
Android 车载串口开发笔记:UART、RS232、RS485、串口配置与数据通信
android
YF021114 小时前
遥控器APP端自动重连方案
android