【问题标题】:react-native picker styling custom fontreact-native 选择器样式自定义字体
【发布时间】:2018-02-20 16:30:31
【问题描述】:

我正在使用我在 res/values/styles.xml 中的 styles.xml 文件中成功自定义的 Picker 组件:

<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:spinnerItemStyle">@style/SpinnerItem</item>
<item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item>
</style>

<style name="SpinnerItem">
<item name="android:fontFamily">Lato-Bold</item>
<item name="android:textSize">20dp</item>
</style>
<style name="SpinnerDropDownItem">
<item name="android:fontFamily">Lato-Bold</item>
<item name="android:padding">10dp</item>
<item name="android:textSize">16dp</item>
<item name="android:textColor">#ffffff</item>
<item name="android:background">#000000</item>
</style>
</resources>

目前我的自定义 fontFamily: Lato-Bold 被忽略。有谁知道如何使用自定义 Spinner 字体?

【问题讨论】:

  • 也对此感兴趣,我尝试使用以下说明添加字体:developer.android.com/guide/topics/ui/look-and-feel/…,但没有任何运气。如果我在 res/font 目录中添加新字体“quicksand”,这对我不起作用。

标签: android react-native


【解决方案1】:

按照官方步骤here,我能够使用自定义字体系列。

但是,当我遵循该指南时,有些事情并不是那么清楚,所以这里总结了您需要采取的步骤(请不要跳过阅读官方指南,因为这只是对它的补充) :

  1. 新建字体资源目录(res/font)
  2. 在那里添加您的字体文件。您的文件名不应包含a-z0-9_ 之外的任何字符(必须为小写)。示例:res/font/lato_bold.ttf
  3. 创建字体系列文件。在我们的示例中,它将是 res/font/lato.xml 并具有以下内容:
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
    <font
        android:fontStyle="normal"
        android:fontWeight="700"
        android:font="@font/lato_bold" />
</font-family>
  1. 在您的自定义样式中引用您的字体,如下所示:
<item name="android:fontFamily">@font/lato_bold</item>

【讨论】:

    猜你喜欢
    • 2017-02-27
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    • 1970-01-01
    相关资源
    最近更新 更多