我在我的应用程序中添加了对2种可下载字体的支持。我通过Android Studio添加了这些字体,为我生成preloaded_fonts.xml
font_certs.xml
等必要文件。
roboto
- 正常的textStyle。roboto_bold
- 用于斜体textStyle(我知道我使用roboto_bold作为斜体textStyle)。我创建了一个新的Font资源文件。
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<font
android:font="@font/roboto"
android:fontStyle="normal"
android:fontWeight="400"
app:font="@font/roboto"
app:fontStyle="normal"
app:fontWeight="400" />
<font
android:font="@font/roboto_bold"
android:fontStyle="italic"
android:fontWeight="400"
app:font="@font/roboto_bold"
app:fontStyle="italic"
app:fontWeight="400" />
</font-family>
我正在以下列方式使用它。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/custom_font"
android:text="Hello World!"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/custom_font"
android:text="Hello World!"
android:textStyle="italic" />
但这不起作用。如果我直接使用roboto
和roboto_bold
,那么它的效果非常好。当我使用捆绑字体时,这也可以正常工作。但是在创建自定义字体系列并使用可下载字体时,它并不起作用。有没有其他人面对这个问题?请帮忙。