【问题标题】:Changing the font of a numberPicker - XML style doesn't change the font on Runtime更改 numberPicker 的字体 - XML 样式不会更改运行时的字体
【发布时间】:2020-09-27 14:00:13
【问题描述】:

我在我想要更改字体、颜色和字体大小的 Android 应用程序中使用 NumberPicker。

我环顾四周,在这里找到了这个解决方案:Setting typeFace to NumberPicker

所以我定义了我的风格如下:

<style name="NumberPickerText">
    <item name="android:textSize">24sp</item>
    <item name="android:textColorPrimary">@color/colorPrimary</item>
    <item name="android:fontFamily">@font/poppins_light</item>
</style>

并将其应用于我的 NumberPicker,如下所示:

<NumberPicker
    android:id="@+id/durationPicker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:descendantFocusability="blocksDescendants"
    android:theme="@style/NumberPickerText"/>

在 XML 设计窗口中查看我的活动时,它看起来就是我想要的样子。但是,当我在手机上运行该应用程序时,颜色和字体大小都按预期应用,但字体不是“Poppins”而是默认字体。

为什么我的字体在 XML 设计窗口中按预期显示,但在运行时显示不同?我怎样才能让字体如愿出现在运行时?

非常感谢您的帮助!

【问题讨论】:

    标签: android typeface numberpicker


    【解决方案1】:

    我仍然不知道为什么会出现这种行为,但是当使用另一种方法更改字体时,它可以工作。我使用的方法如下:https://stackoverflow.com/a/33340382/14349772

    我最初没有使用此解决方案,因为我在扩展 NumberPicker 类时遇到了一个无法解决的错误,我在与我的 ActivityMain 相同的文件中执行了此操作。为 CustomNumberPicker 创建一个单独的文件有助于克服该错误。现在一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-15
      • 1970-01-01
      • 2011-12-02
      • 2011-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多