Android Studio TextView fontFamily无法在主题中使用

时间:2018-04-04 02:11:09

标签: android xml android-studio fonts font-family

我的activity_main.xml中有一个TextView,我想更改其fontFamily属性。它适用于AppTheme和AppCompat主题:

working

但是,在材质主题等其他主题中,字体系列始终设置为默认值:

not working

主题是不支持这些字体还是我做错了什么?

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>

4 个答案:

答案 0 :(得分:2)

尝试将您的活动类别从extend Activity更改为extend AppCompatActivity。它对我有用

答案 1 :(得分:2)

使用androidx.appcompat.widget.AppCompatTextView

代替TextView。

答案 2 :(得分:0)

尝试在您的xml中同时使用app:fontFamilyandroid:fontFamily

答案 3 :(得分:0)

我发生了同样的事情,我正在更改字体系列,但是在模拟器上运行时我的应用程序没有任何更改。幸运的是,我卸下了用于安装该应用程序的USB电缆,将其从最近的应用程序中清除了,再次运行,这一切都很好。字体系列更改为我设置的字体。

相关问题