依赖中导入
compile 'com.hjm:BottomTabBar:1.1.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
activity_main里面的布局 ,引入bottomtabbar的布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:hjm="http://schemas.android.com/apk/res-auto"
>
<com.hjm.bottomtabbar.BottomTabBar
android:id="@+id/bottomtabbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
hjm:tab_divider_height="5dp"
hjm:tab_font_size="20sp"
>
</com.hjm.bottomtabbar.BottomTabBar>
</RelativeLayout>
写好每一个Fragment,这里举例写一个
public class Faxian_Fragment extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_faxian,container,false);
return view;
}
@Override
public void onActivityCreated( Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}
然后在Activit里面初始化bottomtabbar
public class SecondActivity extends AppCompatActivity {
private BottomTabBar bottomTabBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
bottomTabBar = (BottomTabBar) findViewById(R.id.bottomtabbar);
bottomTabBar.init(getSupportFragmentManager())
.setImgSize(70,70)
.setFontSize(20)
.setTabPadding(4,6,10)
.setChangeColor(Color.RED,Color.DKGRAY)
.addTabItem("首页",R.drawable.home_, Shouye_Fragment.class)
.addTabItem("分类",R.drawable.classify, Fenlei_Fragment.class)
.addTabItem("发现",R.drawable.find, Faxian_Fragment.class)
.addTabItem("购物车",R.drawable.cart, GouWuChe_Fragment.class)
.addTabItem("我的",R.drawable.mine, WoDe_Fragment.class)
.isShowDivider(true)
.setOnTabChangeListener(new BottomTabBar.OnTabChangeListener() {
@Override
public void onTabChange(int position, String name) {
}
});
}
}