【问题标题】:Android Studio TextView fontFamily not working in themesAndroid Studio TextView fontFamily 在主题中不起作用
【发布时间】:2018-04-04 02:11:08
【问题描述】:

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

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

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

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>

【问题讨论】:

  • 您是否打算在您的应用程序中包含多个主题?您可以尝试添加任何字体(此处)[developer.android.com/guide/topics/ui/look-and-feel/… 并使其可用于具有所有主题的整个应用程序。
  • 我正在尝试将材料主题与这些字体一起使用
  • @Caleb 你找到解决方案了吗?

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


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    使用 androidx.appcompat.widget.AppCompatTextView

    而不是 TextView。

    【讨论】:

      【解决方案3】:

      尝试将您的活动课程的extend Activity 更改为extend AppCompatActivity。它对我有用

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-10-09
          • 1970-01-01
          • 2018-01-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-08-21
          相关资源
          最近更新 更多