【发布时间】:2020-03-20 06:40:51
【问题描述】:
我目前使用的是平滑底栏库。
【问题讨论】:
-
你的平滑底栏库是否支持徽章。
我目前使用的是平滑底栏库。
【问题讨论】:
您想在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
希望对你有帮助...
【讨论】:
你可以使用材料设计指南来做到这一点from here。另外,不要忘记为android添加材料设计库guide here.
【讨论】:
如果您使用的是 BottomNavigationView,那么这就像小菜一碟一样简单。 BottomNavigationView 提供 BadgeDrawable API,您可以使用它来显示动态信息,例如待处理的请求数。
根据谷歌文档
默认情况下,BadgeDrawable 与其锚点视图的顶部和结束边缘对齐(有一些偏移)。调用 #setBadgeGravity(int) 将其更改为其他支持的模式之一。
注意:这仍在开发中,可能不支持 Android 组件通常支持的全部自定义 Material(例如主题属性)。
您可以在此处查看 BadgeDrawable API 文档的详细信息 https://developer.android.com/reference/com/google/android/material/badge/BadgeDrawable
【讨论】: