Shu*_*shi 5 android material-components material-components-android
我只想补充徽章了menuItem
的BottomNavigationView
我的应用程序。我使用的BottomNavigationView
是材料组件库(版本1.1.0-alpha08),因为它的最新版本是在7天前发布的,所以我没有找到与此相同的任何教程,因为该版本的BottomNavigationView
“的showBadge方法,我们不能使用该方法。
我试过了的实例调用getBadge
和getOrCreateBadge
方法BottomNavigationView
。
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);
Run Code Online (Sandbox Code Playgroud)
我在android开发中是菜鸟,所以如果有人可以提供详细解决此问题的方法,这将非常感激我。
build.gradle
: implementation 'com.google.android.material:material:version'
获取版本
Material Component Theme
如下形式: 您的应用级主题
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
活动代码:
int menuItemId = btmNavView.getMenu().getItem(0).getItemId(); //0 menu item index.
BadgeDrawable badgeDrawable = btmNavView.getOrCreateBadge(menuItemId);
badgeDrawable.setVisible(true);
badgeDrawable.setNumber(1); //1 represents badge value.
Run Code Online (Sandbox Code Playgroud)
XML布局:
<com.google.android.material.bottomnavigation.BottomNavigationView
style="@style/Widget.Design.BottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="@menu/bottom_nav_menu"/>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
742 次 |
最近记录: |