Downloadable Font’s font weight not working android

Issue

I was following this official guide and wanted to use Poppins font for my project. The font has changed but the font weight property does not seem to be work.

I have a style defined as follows:

<style name"TextAppearance.SectionTitle" parent"TextAppearance.MaterialComponents.Headline4">
    <item name"android:textSize">16sp</item>
    <item name"android:textColor">#223263</item>
    <item name"android:fontWeight">700</item>
    <item name"fontWeight">700</item>
</style>

And I’m applying it as follows:

<TextView
    ...
    android:layout_width"wrap_content"
    android:layout_height"wrap_content"
    android:text"@string/category"
    android:textStyle"bold"
    android:textFontWeight"700"
    style"@style/TextAppearance.SectionTitle"
/>

As you can see, I have tried it in several ways but none have been successful yet. The color of the font and size changes according to the style I have defined but the bold effect is not registered.

This is the output I get:

enter image description here

Expected output:

enter image description here

My poppins.xml:

<?xml version"1.0" encoding"utf-8"?>
<font-family xmlns:app"http://schemas.android.com/apk/res-auto"
    app:fontProviderAuthority"com.google.android.gms.fonts"
    app:fontProviderPackage"com.google.android.gms"
    app:fontProviderQuery"Poppins"
    app:fontProviderCerts"@array/com_google_android_gms_fonts_certs">
</font-family>

preloaded_fonts.xml:

<?xml version"1.0" encoding"utf-8"?>
<resources>
  <array name"preloaded_fonts" translatable"false">
    <item>@font/poppins</item>
    <item>@font/poppins_bold</item>
  </array>
</resources>

Solution

I’m not sure if this is the proper fix but I managed to solve it by replacing the font weight with font family inside my style tag as follows:

<style name"TextAppearance.SectionTitle" parent"TextAppearance.MaterialComponents.Headline4">
    ...
    <item name"android:fontFamily">@font/poppins_bold</item>
    <item name"fontFamily">@font/poppins_bold</item>
</style>

You need to add the bold font of your selected font in your resources for this:

Adding bold version of the font

Answered By – Rubek Joshi

Leave a Comment