'fontFamily Unknown resource type Android Studio

i use Android Studio 2020.3.1 Patch 3

how i fix this error Unknown resource type fonts

textview code

<TextView
            android:id="@+id/descTextView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="16dp"
            android:fontFamily="@fonts/zaxo"
            android:gravity="start"
            android:textAlignment="viewStart"
            android:textSize="@dimen/font_body_size"
            app:font='@{"normal"}'
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/titleTextView"
            tools:text="Description"/>

i also created folder font see picture see picture

see error

i also added this line in style.xml

    <item name="android:fontFamily">@fonts/zaxo</item>

and also i added added my font to Utils.java

  public static Typeface getTypeFace(Context context, Fonts fonts) {

       if (currentTypeface == fonts) {
           if (fromAsset == null) {
               if (fonts == Fonts.NOTO_SANS) {
                   fromAsset = Typeface.createFromAsset(context.getAssets(), "fonts/NotoSans-Regular.ttf");
               } else if (fonts == Fonts.ROBOTO) {
//                    fromAsset = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Regular.ttf");
                   fromAsset = Typeface.createFromAsset(context.getAssets(), "fonts/Product-Sans-Regular.ttf");
               } else if (fonts == Fonts.ROBOTO_MEDIUM) {
                   fromAsset = Typeface.createFromAsset(context.getAssets(), "fonts/Product-Sans-Bold.ttf");
               } else if (fonts == Fonts.ROBOTO_LIGHT) {
                   fromAsset = Typeface.createFromAsset(context.getAssets(), "fonts/Product-Sans-Regular.ttf");
               } else if (fonts == Fonts.MM_FONT) {
                   fromAsset = Typeface.createFromAsset(context.getAssets(), "fonts/mymm.ttf");
               }
               else if (fonts == Fonts.KURDI) {
                   fromAsset = Typeface.createFromAsset(context.getAssets(), "fonts/zaxo.ttf");
               }

           }
       } else {
           if (fonts == Fonts.NOTO_SANS) {
               fromAsset = Typeface.createFromAsset(context.getAssets(), "fonts/NotoSans-Regular.ttf");
           } else if (fonts == Fonts.ROBOTO) {
//                fromAsset = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Regular.ttf");
               fromAsset = Typeface.createFromAsset(context.getAssets(), "fonts/Product-Sans-Regular.ttf");
           } else if (fonts == Fonts.ROBOTO_MEDIUM) {
               fromAsset = Typeface.createFromAsset(context.getAssets(), "fonts/Product-Sans-Bold.ttf");
           } else if (fonts == Fonts.ROBOTO_LIGHT) {
               fromAsset = Typeface.createFromAsset(context.getAssets(), "fonts/Product-Sans-Regular.ttf");
           } else if (fonts == Fonts.MM_FONT) {
               fromAsset = Typeface.createFromAsset(context.getAssets(), "fonts/mymm.ttf");
           } else if (fonts == Fonts.KURDI) {
               fromAsset = Typeface.createFromAsset(context.getAssets(), "fonts/zaxo.ttf");
           } else {
               fromAsset = Typeface.createFromAsset(context.getAssets(), "fonts/Product-Sans-Regular.ttf");
           }


           //fromAsset = Typeface.createFromAsset(activity.getAssets(), "fonts/Roboto-Italic.ttf");
           currentTypeface = fonts;
       }
       return fromAsset;
   }

   public static SpannableString getSpannableString(Context context, String str, Fonts font) {
       spannableString = new SpannableString(str);
       spannableString.setSpan(new PSTypefaceSpan("", Utils.getTypeFace(context, font)), 0, spannableString.length(),
               Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
       return spannableString;
   }

when i click this icon i did not find my font see picture

thanks



Solution 1:[1]

you need to keep the 'font' folder under 'res' folder and also it is 'font' not 'fonts'

check this link on how to add fonts

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 shah