我需要在 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" />
Run Code Online (Sandbox Code Playgroud)
但它只显示普通文本,没有 SmallCaps 效果。我也尝试以编程方式设置它 ( text1.fontFeatureSettings = "smcp") 但也没有成功。
如何在 Android 中制作 SmallCaps 文本?为什么 fontFeatureSettings 不起作用?
为了使此功能起作用,您必须拥有一种实际具有 Small Caps 字符的字体 - 从而使其工作通过app:fontFamily(android:fontFamily)例如通过 Small Caps 的字体Aller Display,然后使用android:fontFeatureSettings="smcp"使其成为 Small Caps。
希望能帮助到你
编辑
正如@Cliabhach 在评论中指出的那样,在代码中它看起来像
text1.typeface = resources.getFont(R.font.Aller_Display)
text1.fontFeatureSettings = "smcp"
Run Code Online (Sandbox Code Playgroud)
编辑2
请记住 对于那些不知道的人 - Small Caps 仅适用于小写字符
| 归档时间: |
|
| 查看次数: |
582 次 |
| 最近记录: |