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

完成~

相关推荐
simplepeng7 小时前
我的天,我真是和androidx的字体加载杠上了
android
小猫猫猫◍˃ᵕ˂◍8 小时前
备忘录模式:快速恢复原始数据
android·java·备忘录模式
CYRUS_STUDIO10 小时前
使用 AndroidNativeEmu 调用 JNI 函数
android·逆向·汇编语言
梦否10 小时前
【Android】类加载器&热修复-随记
android
徒步青云10 小时前
Java内存模型
android
今阳11 小时前
鸿蒙开发笔记-6-装饰器之@Require装饰器,@Reusable装饰器
android·app·harmonyos
sunnyday042615 小时前
MyBatis XML映射文件中的批量插入和更新
xml·java·mysql·mybatis
-优势在我15 小时前
Android TabLayout 实现随意控制item之间的间距
android·java·ui
hedalei15 小时前
android13修改系统Launcher不跟随重力感应旋转
android·launcher
Indoraptor17 小时前
Android Fence 同步框架
android