android - 在样式中使用 font.xml 应用自定义字体,支持库 26.0.1

标签 android xml android-fonts

我正在尝试使用 API 26 中引入的 fontFamily 样式。

<style name="customfontstyle" parent="@android:style/TextAppearance.Medium">
    <item name="fontFamily">@font/LDFComicSans.ttf</item>
</style>

文档说:

Using the support library

The Support Library 26.0 provides support to the Fonts in XML feature on devices running Android API version 14 and higher.

如果我使用 android 前缀,它会说 fontFamily 需要最低 API 级别 16。

<style name="customfontstyle" parent="@android:style/TextAppearance.Medium">
    <item name="android:fontFamily">@font/LDFComicSans.ttf</item>
</style>

当我使用“fontFamily”时,我无法使用带有支持库的样式来应用字体。

支持库版本:26.0.1

最佳答案

<style name="PrimaryFontTheme" parent="TextAppearance.AppCompat">
    <item name="android:textSize">14sp</item>
    <item name="android:layout_margin">5dp</item>
    <item name="android:textColor">#898282</item>
    <item name="android:fontFamily">@font/roboto_regular</item>
</style>

I just applied attribute "android:fontFamily" and Its working well :) Problem Solved

关于android - 在样式中使用 font.xml 应用自定义字体,支持库 26.0.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45853622/

相关文章:

android - 屏幕底部的白线(LinearLayout)

android - 如何在 viewModel Kotlin Android 中保护安全?

Android 到服务器上的 App Engine GRPC 空指针

xml - 直接与间接嵌套结构

android - 为安卓制作我自己的字体

Android 使用自定义字体将 HTML 文本显示为粗体

android - "android:theme"属性忽略重力

xml - 如何将 xml 节点捕获到哈希中?

android - 如何在自定义适配器上实现 onClickListener?

android - 使用 json 的泰卢固语文本