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

完成~

相关推荐
2501_944448005 分钟前
Flutter for OpenHarmony衣橱管家App实战:意见反馈功能实现
android·javascript·flutter
风流倜傥唐伯虎9 分钟前
./gradlew assembleDebug和gradle build区别
android·android studio
有位神秘人9 分钟前
Android中获取当前设备的宽高与屏幕密度等数据的工具类
android
那年我七岁9 分钟前
android ndk c++ 绘制图片方式
android·c++·python
Java后端的Ai之路9 分钟前
【Python教程10】-开箱即用
android·开发语言·python
2601_9498095917 分钟前
flutter_for_openharmony家庭相册app实战+隐私设置实现
android·javascript·flutter
我命由我1234519 分钟前
Android 开发 Room 数据库升级问题:A migration from 6 to 7 was required but not found.
android·java·java-ee·android studio·android jetpack·android-studio·android runtime
2601_9495430137 分钟前
Flutter for OpenHarmony垃圾分类指南App实战:资讯详情实现
android·java·flutter
JMchen12311 小时前
现代Android图像处理管道:从CameraX到OpenGL的60fps实时滤镜架构
android·图像处理·架构·kotlin·android studio·opengl·camerax
快点好好学习吧12 小时前
phpize 依赖 php-config 获取 PHP 信息的庖丁解牛
android·开发语言·php