一、 添加依赖
implementation 'com.hjm:BottomTabBar:1.2.2'
二、xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" xmlns:hjm="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <com.hjm.bottomtabbar.BottomTabBar android:id="@+id/bottom_bar" android:layout_width="match_parent" android:layout_height="match_parent" hjm:tab_bar_background="#FFFFFF" hjm:tab_divider_background="#373737" hjm:tab_font_size="28px" hjm:tab_img_font_padding="6dp" hjm:tab_img_height="50px" hjm:tab_img_width="50px" hjm:tab_isshow_divider="true" hjm:tab_padding_bottom="4px" hjm:tab_padding_top="10px" hjm:tab_selected_color="#2784E7" hjm:tab_unselected_color="#282828"> </com.hjm.bottomtabbar.BottomTabBar> </LinearLayout>三、ManinActivity
mBottomBar = findViewById(R.id.bottom_bar); mBottomBar.init(getSupportFragmentManager(), 750, 1334) .setImgSize(50, 50) .setFontSize(28).setTabPadding(10, 6, 4) .setChangeColor(Color.parseColor("#2784E7"), Color.parseColor("#282828")) .addTabItem("首页", R.drawable.ic_vehicle, R.drawable.www, OneFragment.class) .addTabItem("热点", R.drawable.ic_vehicle, R.drawable.www, TwoFragment.class) .addTabItem("发布", R.drawable.ic_vehicle, R.drawable.www, ThreeFragment.class) .addTabItem("我的", R.drawable.ic_vehicle, R.drawable.www, FourFragment.class) .isShowDivider(true) .setDividerColor(Color.parseColor("#373737")) .setTabBarBackgroundColor(Color.parseColor("#FFFFFF")) .setOnTabChangeListener(new BottomTabBar.OnTabChangeListener() { @Override public void onTabChange(int position, String name, View view) { //点击取消红点 if (position == 1){ mBottomBar.setSpot(1, false); }else if (position == 2){ mBottomBar.setSpot(2, false); }else if (position == 3){ mBottomBar.setSpot(3, false); } } }) //图标上小红点 .setSpot(1, true) .setSpot(2, true) .setSpot(3, true);