我想在我的 font_family.xml
中添加自定义粗体字体。我没有在 font family developer doc 中找到粗体 fontStyle="bold"
.它只有normal
或italic
属性。这是font_family.xml
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="@font/lobster_regular" />
<font
android:fontStyle="italic"
android:fontWeight="400"
android:font="@font/lobster_italic" />
</font-family>
所以我必须使用像
这样的风格<style name="fontBoldStyle" parent="@android:style/TextAppearance.Small">
<item name="android:fontFamily">@font/montserrat_semi_bold</item>
</style>
或者像这样
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/montserrat_semi_bold"/>
我的问题
fontStyle
属性有什么作用?即使我没有为font_family.xml
提供斜体字体,并设置textStyle="italic"
然后我的字体是斜体。- 如何在字体系列中添加自定义粗体字体并在
font_family.xml
中设置android:fontStyle="bold"
所以我不必创建不同的样式,我只是必须设置textStyle="bold"
那么我可以设置 3 种字体的解决方案 - normal, bold, italic
到 font_family.xml,并设置 android:fontFamily="@font/font_family"
在 TextView 上,然后我可以使用 android:textStyle="bold"
或斜体,或正常?
最佳答案
对于您的第二个问题:
您可以在 font-family
中添加自定义粗体字体, 通过用 fontWeight="700"
定义字体:
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="@font/lobster_regular" />
<font
android:fontStyle="italic"
android:fontWeight="400"
android:font="@font/lobster_italic" />
<font
android:fontStyle="normal"
android:fontWeight="700"
android:font="@font/montserrat_semi_bold" />
</font-family>
如果 TextView
使用这个 font-family
与 textStyle="bold"
,它将显示在 montserrat_semi_bold
关于android - 如何使用属性 android :fontStyle ="bold" 在 font_family.xml 中设置自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50056263/