【问题标题】:Change BadgeDrawable Typeface in Android在 Android 中更改 BadgeDrawable 字体
【发布时间】:2021-02-21 11:22:44
【问题描述】:

我需要为BadgeDrawable 使用自定义字体出现在我的底部导航栏项目的顶部。所以我为徽章创建了一个自定义样式,如下所示:

<style name="CustomBadge" parent="Widget.MaterialComponents.Badge">
    <item name="badgeGravity">BOTTOM_END</item>
    <item name="android:typeface">@font/custom_font</item>
</style>

并使用此行将其应用于我的默认应用程序样式:

<item name="badgeStyle">@style/CustomBadge</item>

虽然badgeGravity 部分工作正常,因为我看到了变化,但android:typeface 根本不起作用。我也试过fontfontFamily(有和没有android: 前缀),但它们也不起作用。 我正在使用这个版本的材料库:

implementation 'com.google.android.material:material:1.3.0-alpha03'

【问题讨论】:

    标签: android android-studio material-design android-styles material-components-android


    【解决方案1】:

    您可能需要更改TextAppearance 样式

    而不是

    <item name="android:typeface">@font/custom_font</item>
    

    <item name="android:textAppearance">TextAppearanceCustom.Badge</style>
    

    并创建一些如下所示的样式

    <style name="TextAppearanceCustom.Badge" parent="TextAppearance.MaterialComponents.Badge">
        <item name="android:typeface">@font/custom_font</item>
    </style>
    

    查看original file中的所有可用选项

    【讨论】:

    猜你喜欢
    • 2019-11-14
    • 2020-03-27
    • 2012-06-01
    • 1970-01-01
    • 2011-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多