Java android studio的自定义字体在设备上不起作用

Java android studio的自定义字体在设备上不起作用,java,android,xml,fonts,Java,Android,Xml,Fonts,我正在尝试在我的android应用程序上应用自定义字体,不仅仅是一些小部件,还包括整个文本 因此,我创建了一个字体资源目录并添加了字体文件(.otf),但我也尝试了.ttf) 然后,我在style.xml的应用程序主题引用的值目录中添加了font_style.xml 所以我可以看到它在预览中工作 但在我的真实设备中,它不工作 显示设备设置的基本字体 我的密码在这里 /font/nanum_barun_pen_font_family.xml 我尝试将这种方法应用于新的空android项目(相同的

我正在尝试在我的android应用程序上应用自定义字体,不仅仅是一些小部件,还包括整个文本

因此,我创建了一个字体资源目录并添加了字体文件(
.otf
),但我也尝试了
.ttf

然后,我在style.xml的应用程序主题引用的值目录中添加了font_style.xml

所以我可以看到它在预览中工作

但在我的真实设备中,它不工作

显示设备设置的基本字体

我的密码在这里

/font/nanum_barun_pen_font_family.xml
我尝试将这种方法应用于新的空android项目(相同的sdk版本),但在这方面效果很好

我不知道为什么它不工作,只有这个应用

最后,我尝试直接应用字体系列,结果是一样的

为什么


如果您使用的是
TextView
,请帮助我,然后将
TextView
更改为
android.support.v7.widget.AppCompatTextView.
,应该可以使用


希望这能对您有所帮助。

我使用androidx,因此无法为android.support.v7.widget.AppCompatTextView充气。我尝试使用androidx.appcompat.widget.AppCompatTextView,但仍然没有改变。。。。。
/font/nanum_barun_pen_font_family.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">

<!--For API 26 ++ -->
<font
    android:fontStyle="normal"
    android:fontWeight="400"
    android:font="@font/nanumbarunpenr" />

<!--For under API 26-->
<font
    app:fontStyle="normal"
    app:fontWeight="400"
    app:font="@font/nanumbarunpenr"/>
</font-family>
/res/value/font_style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Custom font 적용 -->
    <style name="customTextViewFontStyle" parent="@android:style/Widget.DeviceDefault.TextView">
        <item name="android:fontFamily">@font/nanum_barun_pen_font_family</item>
    </style>

    <style name="customButtonFontStyle" parent="@android:style/Widget.DeviceDefault.Button.Borderless">
        <item name="android:fontFamily">@font/nanum_barun_pen_font_family</item>
    </style>

    <style name="customEditTextFontStyle" parent="@android:style/Widget.DeviceDefault.EditText">
        <item name="android:fontFamily">@font/nanum_barun_pen_font_family</item>
    </style>

    <style name="customRadioButtonFontStyle" parent="@android:style/Widget.DeviceDefault.CompoundButton.RadioButton">
        <item name="android:fontFamily">@font/nanum_barun_pen_font_family</item>
    </style>

    <style name="customCheckboxFontStyle" parent="@android:style/Widget.DeviceDefault.CompoundButton.CheckBox">
        <item name="android:fontFamily">@font/nanum_barun_pen_font_family</item>
    </style>

    <style name="customfontstyle" parent="@android:style/TextAppearance.Small">
        <item name="android:fontFamily">@font/nanum_barun_pen_font_family</item>
    </style>
</resources>
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/red</item>
        <item name="colorAccent">@color/colorAccent</item>

        <!--Apply custom font-family-->
        <item name="android:textViewStyle">@style/customTextViewFontStyle</item>
        <item name="android:buttonStyle">@style/customButtonFontStyle</item>
        <item name="android:editTextStyle">@style/customEditTextFontStyle</item>
        <item name="android:radioButtonStyle">@style/customRadioButtonFontStyle</item>
        <item name="android:checkboxStyle">@style/customCheckboxFontStyle</item>
    </style>

</resources>
...
ext {
    supportLibraryVersion = '28.0.0'
    GsonVersion = '2.8.6'
    retrofitVersion = '2.7.1'
}

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "..."
        minSdkVersion 21
        targetSdkVersion 29
...