如果看不见图片请移动至谷歌浏览器观看,谢谢。
简介:
Bubble Navigation是一个轻巧的库,可通过大量自定义选项轻松制作精美的导航栏。
效果展示:
特点:
- 支持API16+
- 自定义程度高
- 轻量级,使用简单方便
- 切换流畅
- 支持两种布局模式
- 添加徽章
- 您可以添加小红点,它具有BubbleToggleView来创建新的UI组件,而不仅仅是导航
简单使用:
1、在app的build.gradle导入依赖
dependencies {
implementation 'com.gauravk.bubblenavigation:bubblenavigation:1.0.7'
}
2、在XML中的体现
<!-- todo 气泡约束布局 使用流程同约束布局 -->
<com.gauravk.bubblenavigation.BubbleNavigationConstraintView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:bnc_mode=""
>
<!-- todo 气泡导航栏view -->
<com.gauravk.bubblenavigation.BubbleToggleView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:bt_active="true"
app:bt_badgeBackgroundColor="@color/green_active"
app:bt_colorActive="@color/blue_active"
app:bt_colorInactive="@color/blue_inactive"
app:bt_icon="@drawable/ic_search"
app:bt_shape="@drawable/transition_background_drawable_search"
app:bt_title="@string/search"
app:bt_padding="10dp"
/>
<!--
TODO PS: 该View就是导航栏中的item,比如导航栏中有3个item,就必须写3个。最大只能写5个
-->
</com.gauravk.bubblenavigation.BubbleNavigationConstraintView>
<!-- todo 气泡线性布局 使用流程同线性布局 -->
<com.gauravk.bubblenavigation.BubbleNavigationLinearView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</com.gauravk.bubblenavigation.BubbleNavigationLinearView>
app:bnc_mode :有三种模式(BubbleNavigationLinearView无法使用)
- spread:平均分配子元素
- packed:以元素重心打包
- inside:内部元素均等分布
BubbleToggleView是BubbleNavigationLinearView和BubbleNavigationConstraintView作用的子组件。 可用于:
- 导航栏的自定义实现
- 创建新的UI组件
- 切换视图
3、常用属性及其描述:
| 属性 | 描述 |
|---|---|
| bt_active | 设置为默认选中状态 |
| bt_colorActive | 处于选中状态时,将此颜色用于图标和标题 |
| bt_colorInctive | 处于非选中状态时,将此颜色用于图标和标题 |
| bt_icon | 设置图标 |
| bt_iconWidth | 设置图标宽度 |
| bt_iconHeigth | 设置图标高度 |
| bt_title | 设置标题 |
| bt_titleSize | 设置标题文字大小 |
| bt_shape | 设置背景形状 |
| bt_showShapeAlways | 设置背景形状可见 |
| bt_shapeColor | 设置形状的颜色 |
| bt_duration | 设置切换动画完成的持续时间(以毫秒为单位) |
| bt_padding | 内边距 |
| bt_titlePadding | 设置标题填充 |
| bt_badgeText | 设置徽章文字 |
| bt_badgeTextSize | 设置徽章文字大小 |
| bt_badgeTextColor | 设置徽章文字颜色 |
| bt_badgeBackgroundColor | 设置徽章背景色 |
4、一些基本使用:
// TODO 导航栏切换改变Viewpager
mNavigationConstraintView.setNavigationChangeListener(new BubbleNavigationChangeListener() {
@Override
public void onNavigationChanged(View view, int position) {
mViewPager.setCurrentItem(position,true);
}
});
| 方法 | 描述 |
|---|---|
| void setCurrentActiveItem(int position) | 切换导航中的item |
| void setTypeface(Typeface typeface) | 更新文字的字体 |
| void setNavigationChangeListener(BubbleNavigationChangeListener listener) | 设置导航更改侦听器 |
| int getCurrentActiveItemPosition() | 返回当前有效位置 |
| void setBadgeValue(int position, String value) | 更新相应的徽章文本值 |
官方的Github地址 点击跳转
(官方的demo使用的是Kotlin编码的)
这个是博主写的Demo(java编码的哦):点击跳转
希望我的这篇博客能帮助到你
喜欢博主的可以点个赞再走嘛