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

完成~

相关推荐
MinQ30 分钟前
binder和socket区别及原理
android
Ehtan_Zheng1 小时前
Jetpack Compose 中绘制发光边框的多种方式
android
智塑未来1 小时前
像素蛋糕安卓版 AI 专业修图全场景输出高清成片
android·人工智能
陆业聪3 小时前
让 Android 里的 AI 真正「干活」:Function Calling 工程实现全解
android·ai·kotlin
毕设源码-赖学姐3 小时前
【开题答辩全过程】以 基于Android的服装搭配APP为例,包含答辩的问题和答案
android
qq_717410013 小时前
Add Baidu NLP for projects without GMS packages
android
AI-小柒3 小时前
DataEyes 聚合平台 + Claude Code Max 编程实战
android·开发语言·人工智能·windows·python·macos·adb
优选资源分享5 小时前
椒盐音乐 v11.1.0 丨安卓无广本地音乐播放器
android
xiangxiongfly9156 小时前
Android ArrayMap源码分析
android·arraymap
Predestination王瀞潞7 小时前
6.3.1 软件->W3C XPath 1.0 标准(W3C Recommendation):XPath(XML Path Language)查询语言
xml·数据库·oracle