gpt4 book ai didi

android - 可下载字体的字体粗细不适用于android

转载 作者:行者123 更新时间:2023-12-05 06:12:41 25 4
gpt4 key购买 nike

我正在关注 this official guide并想在我的项目中使用 Poppins 字体。字体已更改,但字体粗细属性似乎不起作用。

我有一个定义如下的样式:

<style name="TextAppearance.SectionTitle" parent="TextAppearance.MaterialComponents.Headline4">
<item name="android:textSize">16sp</item>
<item name="android:textColor">#223263</item>
<item name="android:fontWeight">700</item>
<item name="fontWeight">700</item>
</style>

我按如下方式应用它:

<TextView
...
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/category"
android:textStyle="bold"
android:textFontWeight="700"
style="@style/TextAppearance.SectionTitle"
/>

如您所见,我尝试了多种方法,但都没有成功。字体颜色和大小根据我定义的样式变化,但没有注册粗体效果。

这是我得到的输出:

enter image description here

预期输出:

enter image description here

我的 poppins.xml:

<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto"
app:fontProviderAuthority="com.google.android.gms.fonts"
app:fontProviderPackage="com.google.android.gms"
app:fontProviderQuery="Poppins"
app:fontProviderCerts="@array/com_google_android_gms_fonts_certs">
</font-family>

preloaded_fonts.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="preloaded_fonts" translatable="false">
<item>@font/poppins</item>
<item>@font/poppins_bold</item>
</array>
</resources>

最佳答案

我不确定这是否是正确的修复方法,但我设法通过在我的 style 标记内用字体系列替换字体粗细来解决它,如下所示:

<style name="TextAppearance.SectionTitle" parent="TextAppearance.MaterialComponents.Headline4">
...
<item name="android:fontFamily">@font/poppins_bold</item>
<item name="fontFamily">@font/poppins_bold</item>
</style>

为此,您需要在资源中添加所选字体的粗体:

Adding bold version of the font

关于android - 可下载字体的字体粗细不适用于android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63573979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com