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

完成~

相关推荐
胖虎11 天前
Android Studio 读取本地文件(以 ZIP 为例)
android·ide·android studio·本地文件·读取本地文件
出海小纸条1 天前
Google Play 跨应用脚本漏洞(Cross-App Scripting)
android
小孔龙1 天前
Android Runtime(ART) GC 日志手册
android
袁美丽..1 天前
Android --- SystemUI 导入Android Studio及debug
android·ide·android studio
袁美丽..1 天前
Android studio的adb和终端的adb互相抢占端口
android·adb·android studio
鹏多多.1 天前
flutter-使用fluttertoast制作丰富的高颜值toast
android·前端·flutter·ios
守城小轩1 天前
Firefox Android 开发环境搭建全流程(四)
android·firefox·chrome devtools·指纹浏览器·浏览器开发
袁美丽..1 天前
Android --- AOSP源码导入Android Studio
android·android studio
LiuYaoheng1 天前
【Android】View 的基础知识
android·java·笔记·学习
出海小纸条1 天前
Google Play 应用被拒-数据安全表单无效(设备上的应用)
android