//导入依赖
implementation 'com.hjm:BottomTabBar:1.1.1'
//布局文件
<com.hjm.bottomtabbar.BottomTabBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bottomTabBar"
android:layout_alignParentBottom="true"></com.hjm.bottomtabbar.BottomTabBar>
//因为需要有多个fragment所以需要创建多个fragment
//声明控件
private BottomTabBar bottomTabBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zhu);
//得到控件
bottomTabBar = findViewById(R.id.bottomTabBar);
//添加管理者
bottomTabBar.init(getSupportFragmentManager())
.setFontSize(10) //设置字体的大小
.setImgSize(50,50) //设置图片的大小
.setChangeColor(Color.RED,Color.DKGRAY) //设置颜色的改变
.addTabItem("首页",R.mipmap.shouye,FirstFragment.class) //添加文字 图片 fragment
.addTabItem("分类",R.mipmap.fenlei,FenLeiFragment.class)
.addTabItem("购物车",R.mipmap.car,CarFragment.class)
.addTabItem("我的",R.mipmap.wode,MineFragment.class)
.isShowDivider(true); //设置显示分配器
}