Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fontFamily attribute not working via textAppearance

I have next style:

 <style name="Text.Light">
        <item name="android:fontFamily">@font/open_sans_light</item>
    </style>

If I set it to TextView in xml via textAppearance like android:textAppearance="@style/Text.Italic" in design time it shows italic font, but in runtime it doesn't affect. But, if use fontFamily directly in TextView like android:fontFamily="@font/open_sans_italic" it works perfect in both cases (design and runtime). What am I doing wrong? There is my 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"
    xmlns:tools="http://schemas.android.com/tools"
    tools:ignore="UnusedAttribute">

    <font
        android:font="@font/open_sans_regular"
        android:fontStyle="normal"
        android:fontWeight="400"
        app:font="@font/open_sans_regular"
        app:fontStyle="normal"
        app:fontWeight="400" />

    <font
        android:font="@font/open_sans_italic"
        android:fontStyle="italic"
        android:fontWeight="400"
        app:font="@font/open_sans_italic"
        app:fontStyle="italic"
        app:fontWeight="400" />
</font-family>
like image 261
Axbor Axrorov Avatar asked Jan 23 '26 19:01

Axbor Axrorov


1 Answers

The problem was I choose textViewStyle in my AppTheme and there was fontFamily. According to post textAppearance has minimum priority and it can't override other styles which defined in theme or anywhere else.

like image 119
Axbor Axrorov Avatar answered Jan 26 '26 09:01

Axbor Axrorov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!