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

完成~

相关推荐
北漂Zachary1 小时前
四大编程语言终极对比
android·java·php·laravel
学习使我健康5 小时前
Android App 启动原理
android·android studio
TechMix6 小时前
【性能工具】atrace、systrace、perfetto抓取的trace文件有何不同?
android·性能优化
张小潇6 小时前
AOSP15 WMS/AMS系统开发 - 窗口层级源码分析
android·前端
努力努力再努力wz9 小时前
【MySQL入门系列】掌握表数据的 CRUD:DML 核心语法与执行逻辑解析
android·开发语言·数据结构·数据库·c++·b树·mysql
zh_xuan11 小时前
Android gradle任务
android·gradle构建
Grackers11 小时前
Android Perfetto 系列 10:Binder 调度与锁竞争
android·binder
李白你好12 小时前
Android 自动化渗透测试指令生成
android·自动化
CeshirenTester13 小时前
Claude Code 不只是会写代码:这 10 个 Skills,才是效率分水岭
android·开发语言·kotlin
eSsO KERF13 小时前
使用 Logback 的最佳实践:`logback.xml` 与 `logback-spring.xml` 的区别与用法
xml·spring·logback