BottomNavigationBar和其他控件的配合是完全解耦的,日常使用分为BottomNavigationBar+ViewPager 、BottomNavigationBar+FrameLayput
1 使用
- BottomNavigationBar+ViewPager
直接上代码
- BottomNavigationBar+FrameLayput
2 定制
3 BottomNavigationBar角标(小红点)Badges
基本使用
1.如何添加
- 每个item都可以添加badge
- 每个item又一个badges
- 首先创建一个BadgeItem,然后关联到item上
2.类型
- TextBadgeItem
- ShapeBadgeItem
3.代码示例
也可以自定义badgeItem
4.badgeItem方法简介
属性 | 描述 | 方法 | 参数 |
---|---|---|---|
Hide On Select | 选中时隐藏,默认false | setHideOnSelect() | boolean |
Animation Duration | 显示隐藏的动画时间,默认200 | setAnimationDuration() | int毫秒 |
Hide | 隐藏并有动画效果 | hide() | |
Hide with animation control | 隐藏时动画效果,默认有(true) | hide() | boolean |
UnHide/Show | 显示并有动画效果 | show() | |
UnHide/Show with animation control | 显示时动画效果,默认有(true) | show() | boolean |
Toggle | toggles badge between hide/show with animation | toggle() | |
Toggle with animation control | toggles badge between hide/show with/without animation | toggle() | |
Is Hidden | 是否隐藏 | isHidden() | |
Graviy | 设置位置,默认右上角 | setGravity() | Gravity.TOP/BOTTOM/LEFT/RIGHT任意组合 |
5.textBadgeItem方法简介
属性 | 描述 | 方法 | 参数 |
---|---|---|---|
Textt | 设置文本 | setText() | CharSequence |
Text Color | 设置文本颜色,默认白色 | setTextColorResource(), setTextColor() | Resource/ColorCode(String)/Color |
BackgroundColor | 设置背景颜色 | setBackgroundColorResource(), setBackgroundColor() | Resource/ColorCode(String)/Color |
Border Width | 设置border宽度 | setBorderWidth() | int (px值) |
Border Color | 设置border颜色 | setBorderColorResource(), setBorderColor() | Resource/ColorCode(String)/Color |
6.shapeBadgeItem方法简介
属性 | 描述 | 方法 | 参数 |
---|---|---|---|
Shape | 设置形状 | setShape() | SHAPE_OVAL(椭圆), SHAPE_RECTANGLE(矩形), SHAPE_HEART(心形), SHAPE_STAR_3_VERTICES(三角形), SHAPE_STAR_4_VERTICES(菱形), SHAPE_STAR_5_VERTICES(五角星), SHAPE_STAR_6_VERTICES(六角) |
yanse | 设置颜色 | setShapeColorResource(), setShapeColor() | Resource/ColorCode(String)/Color |
Shape Size | 设置宽高 | setSizeInDp(), setSizeInPixels() | int(width and height in pixels/dp) |
Shape Margin | Margin around the shape | setEdgeMarginInDp(), setEdgeMarginInPixels() | int (margin in pixels/dp) |
6.BottomNavigationBar样式
dimens.xml中
Comments | NOTHING