使用说明 https://www.jianshu.com/p/ce8e09cda486
GitHub https://github.com/Vincent7Wong/EasyNavigation
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
/*底部导航栏插件*/
implementation 'com.github.Vincent7Wong:EasyNavigation:1.1.0'
implementation 'com.readystatesoftware.systembartint:systembartint:1.0.3'
布局文件添加
<com.next.easynavigation.view.EasyNavigationBar
android:id="@+id/navigationBar"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.next.easynavigation.view.EasyNavigationBar>
导航栏必要参数
private String[] tabText = {"首页", "新闻", "消息", "我的"};
//未选中icon
private int[] normalIcon = {R.drawable.home_before, R.drawable.news_before, R.drawable.chat_before, R.drawable.me_before};
//选中时icon
private int[] selectIcon = {R.drawable.home_after, R.drawable.news_after, R.drawable.chat_after, R.drawable.me_after};
private List<Fragment> fragments = new ArrayList<>();
导航栏构造
EasyNavigationBar navigationBar = findViewById(R.id.navigationBar);
fragments.add(new HomeFragment());
fragments.add(new NewsFragment());
fragments.add(new WeChatFragment());
fragments.add(new MeFragment());
navigationBar.titleItems(tabText)
.normalIconItems(normalIcon)
.selectIconItems(selectIcon)
.fragmentList(fragments)
.fragmentManager(getSupportFragmentManager())
.build();
其它属性
navigationBar.defaultSetting() //恢复默认配置、可用于重绘导航栏
.titleItems(tabText) // Tab文字集合 只传文字则只显示文字
.normalIconItems(normalIcon) // Tab未选中图标集合
.selectIconItems(selectIcon) // Tab选中图标集合
.fragmentList(fragments) // fragment集合
.fragmentManager(getSupportFragmentManager())
.iconSize(20) //Tab图标大小
.tabTextSize(10) //Tab文字大小
.tabTextTop(2) //Tab文字距Tab图标的距离
.normalTextColor(Color.parseColor("#666666")) //Tab未选中时字体颜色
.selectTextColor(Color.parseColor("#333333")) //Tab选中时字体颜色
.scaleType(ImageView.ScaleType.CENTER_INSIDE) //同 ImageView的ScaleType
.navigationBackground(Color.parseColor("#80000000")) //导航栏背景色
.setOnTabClickListener(new EasyNavigationBar.OnTabClickListener() {
@Override
public boolean onTabSelectEvent(View view, int position) {
//Tab点击事件 return true 页面不会切换
return false;
}
@Override
public boolean onTabReSelectEvent(View view, int position) {
//Tab重复点击事件
return false;
}
})
.smoothScroll(false) //点击Tab Viewpager切换是否有动画
.canScroll(true) //Viewpager能否左右滑动
.mode(EasyNavigationBar.NavigationMode.MODE_ADD) //默认MODE_NORMAL 普通模式 //MODE_ADD 带加号模式
.anim(Anim.ZoomIn) //点击Tab时的动画
.centerTextStr("发现")
.centerImageRes(R.mipmap.add_image)
.centerIconSize(36) //中间加号图片的大小
.centerLayoutHeight(100) //包含加号的布局高度 背景透明 所以加号看起来突出一块
.navigationHeight(60) //导航栏高度
.lineHeight(10) //分割线高度 默认1px
.lineColor(Color.parseColor("#ff0000"))
.centerLayoutRule(EasyNavigationBar.RULE_BOTTOM) //RULE_CENTER 加号居中addLayoutHeight调节位置 EasyNavigationBar.RULE_BOTTOM 加号在导航栏靠下
.centerLayoutBottomMargin(10) //加号到底部的距离
.hasPadding(true) //true ViewPager布局在导航栏之上 false有重叠
.hintPointLeft(-3) //调节提示红点的位置hintPointLeft hintPointTop(看文档说明)
.hintPointTop(-3)
.hintPointSize(6) //提示红点的大小
.msgPointLeft(-10) //调节数字消息的位置msgPointLeft msgPointTop(看文档说明)
.msgPointTop(-10)
.msgPointTextSize(9) //数字消息中字体大小
.msgPointSize(18) //数字消息红色背景的大小
.centerAlignBottom(true) //加号是否同Tab文字底部对齐 RULE_BOTTOM时有效;
.centerTextTopMargin(50) //加号文字距离加号图片的距离
.centerTextSize(15) //加号文字大小
.centerNormalTextColor(Color.parseColor("#ff0000")) //加号文字未选中时字体颜色
.centerSelectTextColor(Color.parseColor("#00ff00")) //加号文字选中时字体颜色
.setMsgPointColor(Color.BLUE) //数字消息、红点背景颜色
.setMsgPointMoreRadius(5) //消息99+角度半径
.setMsgPointMoreWidth(50) //消息99+宽度
.setMsgPointMoreHeight(40) //消息99+高度
.textSizeType(EasyNavigationBar.TextSizeType.TYPE_DP) //字体单位 建议使用DP 可切换SP
.setOnTabLoadListener(new EasyNavigationBar.OnTabLoadListener() { //Tab加载完毕回调
@Override
public void onTabLoadCompleteEvent() {
navigationBar.setMsgPointCount(0, 7);
navigationBar.setMsgPointCount(1, 109);
navigationBar.setHintPoint(4, true);
}
})
//.setupWithViewPager(ViewPager) ViewPager或ViewPager2
.build();
最后修改于 2020-06-16 16:08:00
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付

