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

完成~

相关推荐
时间的拾荒人17 分钟前
MySQL 视图详解
android·数据库·mysql
祉猷并茂,雯华若锦1 小时前
Appium 3.x安卓按键与通知栏操作全指南
android·appium
码农coding2 小时前
android 12 SurfaceFlinger开机启动分析
android
hunterandroid2 小时前
Paging 3 RemoteMediator 实战:构建离线优先的分页列表
android·前端
码农coding2 小时前
android12 开机启动PMS
android
Days20502 小时前
GPT-Image-2 国风美学人设生成提示词分享
android·gpt
浮江雾2 小时前
Flutter第十节-----Flutter布局与组件全解析
android·开发语言·前端·学习·flutter·入门
风起洛阳@不良使3 小时前
spring中xml和注解开发的对比
xml·java·spring
Jomurphys3 小时前
Compose 适配 - 自适应布局(窗口大小类 WindowSizeClasses、列表详情、辅助窗格)
android·compose
plainGeekDev4 小时前
synchronized → Coroutines
android·java·kotlin