2

我需要在 TextView 中显示 SmallCaps 文本。我正在尝试使用下面的代码:

<TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFeatureSettings="smcp"
        android:textColor="@color/black"
        android:textSize="16sp"
        android:text="TEXT" />

但它只是向我显示普通文本,没有 SmallCaps 效果。我也尝试以编程方式设置它(text1.fontFeatureSettings = "smcp")但也没有成功。

如何在 Android 中制作 SmallCaps 文本?为什么 fontFeatureSettings 不起作用?

4

2 回答 2

7

为了使此功能正常工作,您必须拥有一种实际上具有小型大写字母字符的字体 - 因此要使其工作app:fontFamily(android:fontFamily),例如通过使用小型大写字母传递字体Aller Display,然后使用android:fontFeatureSettings="smcp"使其成为小型大写字母。

希望能帮助到你

编辑

正如@Cliabhach 在评论中指出的那样,在代码中它看起来像

    text1.typeface = resources.getFont(R.font.Aller_Display)
    text1.fontFeatureSettings = "smcp"

编辑2

请记住 对于那些不知道的人 - 小型大写字母仅适用于小写字符

于 2020-02-04T10:28:59.257 回答
0

正如您使用的TextView那样,我猜您在运行时为其设置了值,例如说您有一些String对象将被设置为TextView

textView.setText(someStringObj);

因此,您可以通过添加以下内容轻松地将其设置为小写:

textView.setText(someStringObj.toLowerCase());
于 2020-02-04T10:45:05.043 回答