转载自这个项目的github地址:https://github.com/xubinhong/BottomBar
这个底部导航栏的特点:
1.告别xml中的item布局,一切icon、title统统绘制得出;
2.扁平化,由于icon、title都是绘制得出的,所以只需要一个view即可,无需父布局
3.为你处理好碎片切换事务,告别冗余代码,让你从此光速开发
4.不怕需求变动,拔插式体验,增删item,只需修改1行代码
5.源代码十分简单,有助于使用者开发高度适配自身需求的底部
使用方式
1.只需要到给出的github地址中拷贝BottomBar类到你的包下即可,或者自己创建一个类名字叫BottomBar,复制如下代码并导包:
public class BottomBar extends View{
private Context context;
public BottomBar(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
this.context = context;
}
//////////////////////////////////////////////////
//提供的api 并且根据api做一定的物理基础准备
//////////////////////////////////////////////////
private int containerId;
private List<Class> fragmentClassList = new ArrayList<>();
private List<String> titleList = new ArrayList<>();
private List<Integer> iconResBeforeList = new ArrayList<>();
private List<Integer> iconResAfterList = new ArrayList<>();
private List<Fragment> fragmentList = new ArrayList<>();
private int itemCount;
private Paint paint = new Paint();
private List<Bitmap> iconBitmapBeforeList = new ArrayList<>();
private List<Bitmap> iconBitmapAfterList = new ArrayList<>();
private List<Rect> iconRectList = new ArrayList<>();
private int currentCheckedIndex;
private int firstCheckedIndex;
private int titleColorBefore = Color.parseColor("#999999");
private int titleColorAfter = Color.parseColor("#ff5d5e");
private int titleSizeInDp = 10;
private int iconWidth = 20;
private int iconHeight = 20;
private int titleIconMargin = 5;
public BottomBar setContainer(int containerId) {
this.containerId = containerId;
return this;
}
public BottomBar setTitleBeforeAndAfterColor(String beforeResCode, String AfterResCode) {//支持"#333333"这种形式
titleColorBefore = Color.parseColor(beforeResCode);
titleColorAfter = Color.parseColor(AfterResCode);
return this;
}
public BottomBar setTitleSize(int titleSizeInDp) {
this.titleSizeInDp = titleSizeInDp;
return this;
}
public BottomBar setIconWidth(int iconWidth) {
this.iconWidth = iconWidth;
return this;
}
public BottomBar setTitleIconMargin(int titleIconMargin) {
this.title

本文介绍了一个名为BottomBar的自定义View,用于简化Android应用底部导航栏的开发。BottomBar支持扁平化设计,仅需一个View即可完成图标和标题的绘制,大大减少了XML布局的复杂性。它还提供了丰富的API来调整图标和标题的样式,如大小、颜色和间距,以及处理碎片切换,使开发者能够快速实现高度定制化的底部导航栏。
最低0.47元/天 解锁文章
1864

被折叠的 条评论
为什么被折叠?



