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

完成~

相关推荐
Jouzzy7 小时前
【Android安全】Ubuntu 16.04安装GDB和GEF
android·ubuntu·gdb
极客先躯7 小时前
java和kotlin 可以同时运行吗
android·java·开发语言·kotlin·同时运行
Good_tea_h10 小时前
Android中的单例模式
android·单例模式
计算机源码社14 小时前
分享一个基于微信小程序的居家养老服务小程序 养老服务预约安卓app uniapp(源码、调试、LW、开题、PPT)
android·微信小程序·uni-app·毕业设计项目·毕业设计源码·计算机课程设计·计算机毕业设计开题
丶白泽15 小时前
重修设计模式-结构型-门面模式
android
晨春计16 小时前
【git】
android·linux·git
标标大人17 小时前
c语言中的局部跳转以及全局跳转
android·c语言·开发语言
竹林海中敲代码18 小时前
Qt安卓开发连接手机调试(红米K60为例)
android·qt·智能手机
木鬼与槐18 小时前
MySQL高阶1783-大满贯数量
android·数据库·mysql
iofomo18 小时前
【Abyss】Android 平台应用级系统调用拦截框架
android·开发工具·移动端