我需要用SmallCaps在TextView上显示文本。我试图使用下面的代码:
<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"),但也没有成功。
如何在安卓系统中生成SmallCaps文本?为什么fontFeatureSettings不能工作?
发布于 2020-02-04 10:28:59
为了使这个特性工作,您必须有一个实际具有小Caps字符的字体--因此,为了使它能够通过app:fontFamily(android:fontFamily) (例如Aller Display )传递带有小Caps的字体,然后使用android:fontFeatureSettings="smcp"使其成为小Caps。
希望它能帮上忙
编辑
正如@Cliabhach在注释中指出的,在代码中,它将类似于
text1.typeface = resources.getFont(R.font.Aller_Display)
text1.fontFeatureSettings = "smcp"Edit2
要记住,对于那些不认识的人来说,只适用于小写字符。
发布于 2020-02-04 10:45:05
由于您使用的是TextView,所以我猜您在运行时为它设置了值,比如,您有一些String对象,它将被设置为TextView,例如:
textView.setText(someStringObj);因此,通过添加以下内容,您可以轻松地将其设置为小写:
textView.setText(someStringObj.toLowerCase());https://stackoverflow.com/questions/59964956
复制相似问题