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

完成~

相关推荐
飘逸飘逸2 分钟前
Autojs进阶-插件更新记录
android·javascript
Be for thing13 分钟前
Android 传感器硬件原理 + 功耗测试与异常定位实战(手表 / IoT / 手机通用)
android·学习·智能手机
阿拉斯攀登25 分钟前
第 8 篇 RK 平台安卓驱动实战 1:GPIO 输入输出驱动,从内核到 App 全流程打通
android·驱动开发·rk3568·瑞芯微·rk安卓驱动
常利兵28 分钟前
告别SharedPreferences!DataStore+Android Keystore构建安全存储新防线
android·安全
2501_9159184128 分钟前
网站抓包解析,掌握浏览器请求和 HTTPS 数据分析的流程
android·ios·小程序·https·uni-app·iphone·webview
黄林晴37 分钟前
Android 17 要下狠手了:无障碍服务 API 将被严格限制
android
冰语竹40 分钟前
Android学习之表格布局
android
weixin_307779131 小时前
构建健壮的XML文档抓取与摘要流水线:Requests + urllib3.Retry + lxml 实践
xml·开发语言·python·算法·性能优化
00后程序员张1 小时前
iOS开发者工具有哪些?Xcode、AppUploader(开心上架)、Fastlane如何使用
android·macos·ios·小程序·uni-app·iphone·xcode
Kapaseker1 小时前
一杯 Kotlin 美式学透 enum class
android·kotlin