首页 > 解决方案 > BottomNavigationView 中的徽章在主题更改后没有改变颜色

问题描述

我已经在我的 Android 应用程序中实现了主题更改逻辑。不幸的是,当我更改主题并在 BottomNavigationView 中调用重新创建功能徽章时,背景颜色没有改变,请找到我的代码:

    private void setBadge(Integer newMessageCount) {
        BadgeDrawable badge = bottomNav.getOrCreateBadge(R.id.nav_messages);
        badge.setNumber(newMessageCount);
        badge.setBackgroundColor(ThemeColors.getColor(this, R.attr.secondaryColor));
        badge.setBadgeTextColor(ThemeColors.getColor(this, R.attr.secondaryTextColor));
    }
public class ThemeColors {

    public static @ColorInt
    int getColor(Context context, int attrColor) {
        return ContextCompat.getColor(context, getColorResourceId(context, attrColor));
    }

    public static int getColorResourceId(Context context, int attrColor) {
        TypedValue typedValue = new TypedValue();
        context.getTheme().resolveAttribute(attrColor, typedValue, true);
        return typedValue.resourceId;
    }
}

你能告诉我为什么背景颜色没有改变吗?问候

标签: javaandroidthemes

解决方案


推荐阅读