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

完成~

相关推荐
JienDa19 分钟前
JienDa聊PHP:PHP 8革命性特性深度实战报告:枚举、联合类型与Attributes的工程化实践
android·开发语言·php
向葭奔赴♡29 分钟前
Android AlertDialog实战:5种常用对话框实现
android·java·开发语言·贪心算法·gitee
峥嵘life1 小时前
Android EDLA 搭建Linux测试环境简介
android·linux·运维
李坤林1 小时前
Anroid Perfetto
android
2501_915909061 小时前
深度解析 iOS 内存占用,构建多工具协同的内存诊断、监控与优化体系
android·ios·小程序·https·uni-app·iphone·webview
sang_xb1 小时前
深入解析 HashMap:从存储架构到性能优化
android·java·性能优化·架构
啃火龙果的兔子2 小时前
android studio运行下载gradle特别慢怎么处理
android·ide·android studio
qq_296544652 小时前
安卓手机投屏电脑端教程,手机投屏教程,可以手机和电脑互传文件。电脑管理手机文件和APP等操作
android·智能手机·电脑
我的offer在哪里3 小时前
MySQL 高频细节问题(覆盖性能、存储、运维、故障排查,补充前文未深入的核心细节)
android·运维·mysql