Android Studio TextView fontFamily not working in themes
Asked Answered
P

4

5

I have a TextView in my activity_main.xml, and I want to change its fontFamily attribute. It works in the AppTheme and the AppCompat themes:

working

However, in other themes like the Material themes, the font family is always set to default:

not working

Is it that the themes don't support those fonts or I've done something wrong?

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
    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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

<TextView
    android:id="@+id/time"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="This is some text"
    android:textColor="@android:color/background_light"
    android:textSize="50sp"
    app:fontFamily="cursive"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.223" />

</android.support.constraint.ConstraintLayout>
Patras answered 4/4, 2018 at 2:11 Comment(3)
are you planning to have multiple themes in your application? you can try adding any fonts (here)[developer.android.com/guide/topics/ui/look-and-feel/… and make it available to the whole app with all themes.Scheffler
I'm trying to use the material theme with those fontsPatras
@Caleb Did you find a solution?Lesbian
S
6

try to use both app:fontFamily and android:fontFamily in your xml

Ssw answered 25/6, 2018 at 6:56 Comment(0)
C
6

Use androidx.appcompat.widget.AppCompatTextView

instead of TextView.

Coltin answered 16/7, 2020 at 13:12 Comment(0)
J
3

Try to change extend Activity to extend AppCompatActivity for your activity class. It works for me

Jeth answered 21/1, 2020 at 9:8 Comment(0)
O
0

Same thing happened to me, I was changing the font family but no changes in my application when being run on emulator. I ,luckily, removed the usb cable that I was using to install the application, cleared it from recent apps, ran it again and here it was all good. The font family changed to what I set to.

Onondaga answered 7/8, 2020 at 12:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.