有时候需要根据UI需求切换项目字体,步骤如下:
准备字体文件,示例使用ttf文件,新建font文件夹:


将ttf文件放到res/font目录下
设置全局字体,系统主题添加
<item name="android:fontFamily">@font/zcool_gdh_regular</item>
效果对比:


修改单个UI字体
<TextView
android:fontFamily="@font/zcool_gdh_regular"
android:textColor="@color/title_1"
android:text="@{pro.title}"
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
效果:
