当我在
android:textFontWeight
上使用 TextView
属性时,它不会从字体系列中选择适当的字体。我在 API 28 上测试了它,因为该属性仅在 28+ 上可用
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/myfont"
android:text="Hello World!" />
myfont
字体系列定义如下:
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<font
app:fontStyle="normal"
app:fontWeight="400"
app:font="@font/myfont_regular" />
<font
app:fontStyle="normal"
app:fontWeight="200"
app:font="@font/myfont_thin" />
在 API 28 上,我希望
TextView
选择 myfont_thin
,但事实并非如此。我也尝试过其他重量但没有成功。
属性
android:textFontWeight
不支持所有字体。
它适用于例如:
android:fontFamily="sans-serif"
android:fontFamily="serif"
但忽略其他
android:fontFamily="monospace"
android:fontFamily="cursive"