我目前正在使用一个平滑的底栏库。
问问题
224 次
3 回答
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
希望它有帮助...
于 2020-03-20T07:07:10.760 回答
1
你可以使用材料设计指南从这里开始。另外,不要忘记在此处添加 android 指南的材料设计库。
于 2020-03-20T06:52:43.450 回答
1
如果您使用的是 BottomNavigationView,那么这就像小菜一碟一样简单。BottomNavigationView 提供 BadgeDrawable API,您可以使用它来显示动态信息,例如待处理请求的数量。
根据谷歌文档
默认情况下,BadgeDrawable 与其锚视图的顶部和结束边缘对齐(有一些偏移)。调用 #setBadgeGravity(int) 将其更改为其他支持的模式之一。
注意:这仍在开发中,可能不支持 Android 组件通常支持的全部自定义 Material(例如主题属性)。
您可以在此处详细查看 BadgeDrawable API 文档 https://developer.android.com/reference/com/google/android/material/badge/BadgeDrawable
于 2020-03-20T07:12:27.513 回答