Android 如何全局添加自定义字体
如何在android studio中更改自定义字体?做这么简单的事似乎没有简单的方法。我知道您可以更改TextView的字体,但要更改特定元素、抽屉或全局的字体,我似乎找不到解释。就像@tycj在评论中所说的,不幸的是,无法将全局字体设置为TextView。但您可以设置自定义类型样式,并将其作为“textAppearance”应用于TextView。 例如:假设您的项目中有这样的样式Android 如何全局添加自定义字体,android,android-studio,Android,Android Studio,如何在android studio中更改自定义字体?做这么简单的事似乎没有简单的方法。我知道您可以更改TextView的字体,但要更改特定元素、抽屉或全局的字体,我似乎找不到解释。就像@tycj在评论中所说的,不幸的是,无法将全局字体设置为TextView。但您可以设置自定义类型样式,并将其作为“textAppearance”应用于TextView。 例如:假设您的项目中有这样的样式 <style name="MyAPP.TextAppearance.Headline1&quo
<style name="MyAPP.TextAppearance.Headline1" parent="TextAppearance.MaterialComponents.Headline1">
<item name="fontFamily">@font/your_font</item>
<item name="android:textSize">48sp</item>
</style>
@字体/你的
48便士
然后,您只需将其应用于主题。如下所示:
<item name="textAppearanceHeadline1">@style/MyAPP.TextAppearance.Headline1</item>
@style/MyAPP.TextAppearance.Headline1
现在,你可以在文本视图中自由使用它,但正如样式名称所示,最好在你的应用程序中对听者文本视图使用它
<TextView
...
android:textAppearance="?attr/textAppearanceHeadline1" />
好的是,您可以覆盖这些属性
<TextView
...
android:textAppearance="?attr/textAppearanceHeadline1"
android:textSize="36sp" />
要获得更多信息,您可以查看。此外,我建议也检查一下没有任何说明将此字体设置为我应用程序中的所有文本视图,您必须单独设置它们