如何将 android 中可用的默认字体系列设置为操作栏标题

how to set default font family available in android to action bar title

有了 Toolbar 你可以使用:

    <com.google.android.material.appbar.MaterialToolbar
          app:titleTextAppearance="@style/myTitleTextAppearance"

与:

    <style name="myTitleTextAppearance" parent="TextAppearance.MaterialComponents.Subtitle1" parent="TextAppearance.AppCompat.Subhead">
        <item name="fontFamily">sans-serif-medium</item>
        <item name="android:fontFamily">sans-serif-medium</item>
         .....
    </style>

使用 ActionBar 您在应用主题中添加 actionBarStyle 属性:

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
    <item name="actionBarStyle">@style/myActionBar</item>
</style>

与:

<style name="myActionBar" parent="Widget.MaterialComponents.ActionBar.PrimarySurface">
    <item name="titleTextStyle">@style/myActionBarTextTitle</item>
</style>

<style name="myActionBarTextTitle" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="fontFamily">sans-serif-medium</item>
    <item name="android:fontFamily">sans-serif-medium</item>
</style>