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

完成~

相关推荐
用户693717500138415 分钟前
AI Agent 里的 Loop 到底是什么?
android·前端·后端
海天鹰29 分钟前
安卓分割空字符串数组长度为1
android
PixelBai35 分钟前
JSON转XML使用教程:从入门到精通
xml·json
Coffeeee1 小时前
从 Android 15 到 Android 17,谷歌猝不及防的音频改动
android·前端·google
用户69371750013841 小时前
AI 领域的 Harness,到底是什么意思?
android·前端·后端
恋猫de小郭2 小时前
Flutter 开发怎么做 Agent ?从工程实战详细给你解读下
android·前端·flutter
安卓修改大师2 小时前
安卓修改大师实战:Activity生命周期全解析与Smali插桩教程
android
zhangphil2 小时前
Android集成封装libjpeg-turbo解码库,Kotlin语言实现
android
码上有光3 小时前
c++:map和set的底层实现
android·java·c++·set·map
峥嵘life3 小时前
Android GMS 开机向导横竖屏切换配置总结
android·学习