【发布时间】:2019-11-26 03:26:08
【问题描述】:
我只想在我的应用中为BottomNavigationView 中的menuItem 添加徽章。我正在使用 Material Components 库(版本 1.1.0-alpha08)的 BottomNavigationView,因为它是 7 天前发布的最新版本,我没有找到任何相同的教程,现在因为在此进行了更改BottomNavigationView 的 showBadge 方法的版本,我们不能使用该方法。
我尝试通过 BottomNavigationView 的实例调用 getBadge 和 getOrCreateBadge 方法。
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_nav);
if (bottomNavigationView.getBadge(3) == null) {
audioPlayingCountBadge = bottomNavigationView.getOrCreateBadge(3);
audioPlayingCountBadge.setBackgroundColor(
getResources().getColor(R.color.colorPrimaryDark)
);
} else {
audioPlayingCountBadge = bottomNavigationView.getBadge(3);
}
audioPlayingCountBadge.setVisible(true);
如果有人能详细提供这个问题的解决方案,将非常感谢我。
【问题讨论】:
标签: android bottomnavigationview material-components-android material-components