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

完成~

相关推荐
Lei活在当下7 小时前
【项目踩坑实录】并发环境下,Glide缓存引起的图片加载异常
android·debug·glide
my_power52010 小时前
检出git项目到android studio该如何配置
android·git·android studio
三少爷的鞋13 小时前
Repository 方法设计:suspend 与 Flow 的决选择指南(以朋友圈为例)
android
阿里云云原生13 小时前
Android App 崩溃排查指南:阿里云 RUM 如何让你快速从告警到定位根因?
android·java
cmdch201715 小时前
手持机安卓新增推送按钮功能
android
攻城狮201516 小时前
【rk3528/rk3518 android14 kernel-6.10 emcp sdk】
android
何妨呀~16 小时前
mysql 8服务器实验
android·mysql·adb
QuantumLeap丶16 小时前
《Flutter全栈开发实战指南:从零到高级》- 25 -性能优化
android·flutter·ios
木易 士心18 小时前
MVC、MVP 与 MVVM:Android 架构演进之路
android·架构·mvc
百锦再18 小时前
国产数据库的平替亮点——关系型数据库架构适配
android·java·前端·数据库·sql·算法·数据库架构