依赖:
implementation 'com.hjm:BottomTabBar:1.1.1'
implementation 'com.recker.flybanner:flybanner:1.3'
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.2'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation'com.squareup.okhttp3:okhttp:3.7.0'
implementation'com.squareup.okio:okio:1.12.0'
implementation'com.android.support:design:28.0.0'
implementation 'com.google.code.gson:gson:2.8.5'
FragMentActivity .xml布局:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".FragMentActivity">
<com.hjm.bottomtabbar.BottomTabBar
android:id="@+id/frag"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.hjm.bottomtabbar.BottomTabBar>
</LinearLayout>
FragMentActivity .java代码:
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.gy.week2.fragment.BuyFragment;
import com.gy.week2.fragment.FenLeiFragment;
import com.gy.week2.fragment.MiFragment;
import com.gy.week2.fragment.ShouYeFragment;
import com.gy.week2.fragment.WoDeFragment;
import com.hjm.bottomtabbar.BottomTabBar;
public class FragMentActivity extends AppCompatActivity {
private BottomTabBar frag;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frag_ment);
frag = findViewById(R.id.frag);
//初始frag
frag.init(getSupportFragmentManager())
.setImgSize(50,50)
.setFontSize(15)
.setTabPadding(4,6,10)
.setChangeColor(Color.RED,Color.DKGRAY)
.addTabItem("首页",R.drawable.sel_1,ShouYeFragment.class)
.addTabItem("分类",R.drawable.sel_2,FenLeiFragment.class)
.addTabItem("觅Me",R.drawable.sel_3,MiFragment.class)
.addTabItem("购物车",R.drawable.gw,BuyFragment.class)
.addTabItem("我的",R.drawable.sel_4,WoDeFragment.class)
.setOnTabChangeListener(new BottomTabBar.OnTabChangeListener() {
@Override
public void onTabChange(int position, String name) {
}
});
}
}