Android 如何将数字添加到底部栏,如图所示

Android 如何将数字添加到底部栏,如图所示,android,bottombar,Android,Bottombar,我目前正在使用一个平滑的底部栏库。您可以使用“材质设计指南”来完成此操作。另外,别忘了为android添加材质设计库是否要在底部导航视图菜单中添加徽章计数 然后使用MaterialComponents库 使用materialcomponent theme style.xml 在布局文件中 <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottom

我目前正在使用一个平滑的底部栏库。

您可以使用“材质设计指南”来完成此操作。另外,别忘了为android添加材质设计库

是否要在底部导航视图菜单中添加徽章计数

然后使用MaterialComponents库

使用materialcomponent theme style.xml

在布局文件中

<com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottom_nav"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:menu="@menu/bottom_nav_menu"/>
添加徽章计数,如

val bottonnavBar = findViewById<BottomNavigationView>(R.id.bottom_nav)
var badge = bottonnavBar.getOrCreateBadge(R.id.action_add) //R.id.action_add is menu id
badge.number = 2 // it will show count on icon

希望它能帮助您……

如果您使用的是BottomNavigationView,那么这就像小菜一碟一样简单。BottomNavigationView提供了BadgeDrawable API,您可以使用它来显示动态信息,例如一些挂起的请求

根据谷歌文档

默认情况下,BadgeDrawable与其锚定视图的顶部边缘和末端边缘对齐,并带有一些偏移。调用setBadgeGravityint将其更改为其他支持的模式之一

注意:这仍在开发中,可能不支持Android组件通常支持的全部定制材料,例如主题属性

您可以在此处详细查看BadgeDrawable API文档

平滑底栏库是否支持徽章。如果有效,请将其标记为已接受。。。
<com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottom_nav"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:menu="@menu/bottom_nav_menu"/>
val bottonnavBar = findViewById<BottomNavigationView>(R.id.bottom_nav)
var badge = bottonnavBar.getOrCreateBadge(R.id.action_add) //R.id.action_add is menu id
badge.number = 2 // it will show count on icon