xml布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".HomeActivity">
<bwie.com.day8_test.zidingyi.TobBar
android:background="@color/colorAccent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tob"
app:leftButton="@drawable/left"
app:letfText="返回"
app:centerText="标题"
app:rightText="提交"
app:textColor="#FFF2F0F1"
app:textSize="10sp"
></bwie.com.day8_test.zidingyi.TobBar>
<com.hjm.bottomtabbar.BottomTabBar
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="match_parent"></com.hjm.bottomtabbar.BottomTabBar>
</LinearLayout>
主页面
package bwie.com.day8_test;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.hjm.bottomtabbar.BottomTabBar;
import bwie.com.day8_test.fragment.FenleiFragment;
import bwie.com.day8_test.fragment.GouwucheFragment;
import bwie.com.day8_test.fragment.MyFragment;
import bwie.com.day8_test.fragment.ShouFragment;
import bwie.com.day8_test.fragment.XunzhaoFragment;
import bwie.com.day8_test.zidingyi.TobBar;
public class HomeActivity extends AppCompatActivity {
private BottomTabBar bb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
bb = findViewById(R.id.bottomBar);
final TobBar tob= findViewById(R.id.tob);
bb.init(getSupportFragmentManager())
.setImgSize(50 ,50)
.setFontSize(8)
.setTabPadding(4,5,10)
.setChangeColor(Color.BLUE,Color.BLACK)
.addTabItem("首页",R.drawable.ic_sim_card_black_24dp,ShouFragment.class)
.addTabItem("分类",R.drawable.ic_menu_black_24dp,FenleiFragment.class)
.addTabItem("购物车",R.drawable.ic_local_grocery_store_black_24dp,GouwucheFragment.class)
.addTabItem("寻找",R.mipmap.see_true,XunzhaoFragment.class)
.addTabItem("我的",R.mipmap.people_flase,MyFragment.class)
.setOnTabChangeListener(new BottomTabBar.OnTabChangeListener() {
@Override
public void onTabChange(int position, String name) {
tob.setCenter(true,name);
}
});
}
}