您的位置:首页 > 文旅 > 美景 > 【Android】字体设置

【Android】字体设置

2024/10/6 14:28:14 来源:https://blog.csdn.net/qq_45481971/article/details/140993543  浏览:    关键词:【Android】字体设置

需求 :

  1. 全局字体设置 2. 局部字体设置
    既可通过kotlin或者第三方库实现, 也可以android ui上直接实现
    此处讲的是使用Android自带的字体设置

实现 :

1. 字体文件放到src/main/res/font 目录下

2. 局部字体使用 ↓

            <TextViewandroid: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 定义全局字体

<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

    <applicationandroid: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">

完成~

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com