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

完成~

相关推荐
weixin_440784118 分钟前
OkHttp使用指南
android·java·okhttp
Xxtaoaooo21 分钟前
React Native 跨平台鸿蒙开发实战:调试与真机测试全流程
android·react native·harmonyos
TheNextByte122 分钟前
将视频从电脑传输到Android (超简单指南)
android·电脑·音视频
TheNextByte124 分钟前
如何将照片从Android手机传输到Chromebook电脑
android·智能手机·电脑
程序员清洒9 小时前
Flutter for OpenHarmony:GridView — 网格布局实现
android·前端·学习·flutter·华为
running up that hill10 小时前
Android的线性布局
android
m0_7482299910 小时前
Laravel9.x核心特性全解析
android
2603_9494621012 小时前
Flutter for OpenHarmony社团管理App实战:意见反馈实现
android·flutter
错把套路当深情12 小时前
android两种渠道支持一键打包 + 随意组合各种渠道
android
彬sir哥13 小时前
android studio如何把.gradle从C盘移到D盘
android·gradle·maven·android studio