3

I have a style resource for textView

<style name="AppText.Note.Medium">
    <item name="android:textFontWeight" tools:targetApi="p">500</item>
</style>

But it works on API level 28 or higher. Is there any way to use it on API level 23? Or maybe there is some alternative?

DanMan
  • 692
  • 9
  • 22

2 Answers2

2

Support font family on API lower than 26 use

  <item name="fontWeight">500</item>
Dinesh
  • 1,410
  • 2
  • 16
  • 29
0

This works on All api level

<?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">
    <font
        app:font="@font/sdfglay_bold"
        app:fontWeight="700"/>
    <font
        app:font="@font/sdfglay_light"
        app:fontWeight="300"/>
    <font
        app:font="@font/sdfglay_regular"
        app:fontWeight="400"/>
    <font
        app:font="@font/sdfglay_medium"
        app:fontWeight="500"/>
    <font
        app:font="@font/sdfglay_semibold"
        app:fontWeight="600"/>

instaed of this font familily

<com.google.android.material.textview.MaterialTextView
        android:id="@+id/postDesc"
        android:layout_width="0dp"
        android:fontFamily="@font/sdfglay_light"
        android:layout_height="wrap_content"
        android:layout_marginRight="90dp"
        android:ellipsize="end"
        android:paddingVertical="8dp"/>

Use the font with spcifed weight diriectly

        android:fontFamily="@font/sdfglay_light"
Abhijith mogaveera
  • 918
  • 10
  • 16