Я пытаюсь применить пользовательские шрифты в своем приложении android не только к нескольким виджетам, но и к целым текстам.
Поэтому я создал каталог ресурсов шрифта и добавил файл шрифта (.otf
, но я попробовал также .ttf
),
custom-font-family.xml
И затем я добавил font_style. xml в каталог значений, на который ссылается App Theme style. xml
Чтобы я мог видеть он работает в режиме предварительного просмотра ...
Но на моем реальном устройстве он не работает !!
Отображает базовый c шрифт настроек устройства.
my код здесь
/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>
/ res / values / style. xml
<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>
gradle
...
ext {
supportLibraryVersion = '28.0.0'
GsonVersion = '2.8.6'
retrofitVersion = '2.7.1'
}
android {
compileSdkVersion 29
defaultConfig {
applicationId "..."
minSdkVersion 21
targetSdkVersion 29
...
Я пытался применить этот способ в новом пустом проекте android (та же версия SDK), но он хорошо работает на этом ..
Я не знаю, почему не работает только это приложение !!
Наконец, я попытался применить font-family напрямую, это было то же самое.
Почему!?!?
Пожалуйста, помогите мне