我目前正在使用平滑的底部栏库。
答案 0 :(得分:2)
您要在BottomNavigationView
菜单中添加徽章计数吗?
然后使用MaterialComponents
库
implementation 'com.google.android.material:material:1.2.0-alpha03'
使用materialcomponent主题style.xml
<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>
在您的布局文件中
<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
希望有帮助...
答案 1 :(得分:1)
您可以使用材料设计指南来进行from here。另外,别忘了为Android guide here.
添加材料设计库答案 2 :(得分:1)
如果您使用的是BottomNavigationView,那么这就像小菜一碟一样容易。 BottomNavigationView提供了BadgeDrawable API,您可以使用它来显示动态信息,例如许多待处理的请求。
根据Google文档
默认情况下,BadgeDrawable与其锚视图的顶部和末端边缘对齐(有一些偏移)。调用#setBadgeGravity(int)将其更改为其他受支持的模式之一。
注意:这仍在开发中,可能不支持一般Android材质Material组件通常支持的所有自定义范围。
您可以在此处查看BadgeDrawable API文档的详细信息 https://developer.android.com/reference/com/google/android/material/badge/BadgeDrawable