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

完成~

相关推荐
我命由我1234510 小时前
Android 控件 - CardView(快速实现圆角)
android·java·java-ee·kotlin·android studio·android-studio·android runtime
码云数智-园园11 小时前
Android 全方位性能优化合集
android·性能优化
hunterandroid11 小时前
[Android 从零到一] Compose 动画实战:从 AnimatedVisibility 到复杂转场与手势联动
android
Knight_AL12 小时前
Lombok @Builder 踩坑:build() 前后对象类型不一样
android·java·开发语言
大黄说说12 小时前
Android 本地存储深度对比:SharedPreferences、MMKV、Room 数据库怎么选?
android·数据库
阿巴斯甜13 小时前
adb push .../AdapterService.apk 和 .../区别:
android
恋猫de小郭13 小时前
Flutter 的另外一种形态?社区 DartNative 要来了。
android·前端·flutter
我命由我1234513 小时前
Android Drawable - gradient
android·java·java-ee·kotlin·android studio·android-studio·android runtime
Kapaseker14 小时前
AI 时代,读源码还有用吗?从 Kotlin 集合排序说起
android·kotlin
️学习的小王15 小时前
二级MySQL PHP综合应用题完整考点+历年真题风格练习题
android·mysql·php