Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio TextView fontFamily not working in themes

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>
like image 487
gldanoob Avatar asked Apr 04 '18 02:04

gldanoob


2 Answers

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

like image 62
hotHead Avatar answered Sep 27 '22 20:09

hotHead


Use androidx.appcompat.widget.AppCompatTextView

instead of TextView.

like image 31
Sam_ Avatar answered Sep 27 '22 19:09

Sam_