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

完成~

相关推荐
冬奇Lab16 分钟前
相机拍照流程:从快门按下到JPEG存储的完整旅程
android·音视频开发·源码阅读
alexhilton23 分钟前
在Compose中用Shader实现透明的粘稠元球效果
android·kotlin·android jetpack
jwn9992 小时前
Laravel5.x核心特性全解析
android·php·laravel
studyForMokey3 小时前
【Android面试】RecylerView专题
android·spring·面试
android_cai_niao5 小时前
Android中有什么技术过时了可以直接用新技术的
android·过时技术
lingggggaaaa5 小时前
PHP原生开发篇&文件安全&上传监控&功能定位&关键搜索&1day挖掘
android·学习·安全·web安全·php
我是场6 小时前
我的NPI项目 - OTA upgrade是什么?
android·人工智能
zh_xuan6 小时前
Android 实现fragment导航
android·fragment导航
java资料站6 小时前
MySQL 增量同步脚本
android·数据库·mysql
穷人小水滴6 小时前
手机安装 Cross Profile Test App (Android)
android·手机·一加