android:fontFamily
使用支持库 26.1.0,我通过设置应用程序主题的属性,设法为整个应用程序设置了默认字体:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="android:fontFamily">@font/proxima_nova</item>
</style>
proxima_nova.xml
字体资源文件在哪里:
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="UnusedAttribute">
<!-- As of Android Support Library 26.0, we must declare both sets of attributes to ensure
our fonts load on devices running Android 8.0 (API level 26) or lower. -->
<font
android:font="@font/proxima_nova_light"
android:fontStyle="normal"
android:fontWeight="300"
app:font="@font/proxima_nova_light"
app:fontStyle="normal"
app:fontWeight="300" />
<font
android:font="@font/proxima_nova_semibold"
android:fontWeight="600"
app:font="@font/proxima_nova_semibold"
app:fontWeight="600" />
</font-family>