第一步:
在自己工程的App下的build.gradle下添加依赖:
repositories {
jcenter()
}
dependencies{
implementation'com.jpeng:JPTabBar:1.1.2'
}
第二布:
在自己的主页面去布局文件中:
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
<com.jpeng.jptabbar.JPTabBar
app:layout_behavior="@string/bye_burger_bottom_behavior"
android:background="@color/colorWhite"
android:id="@+id/tabBar"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_50"
app:TabIconSize="20dp" />
接下来就是在自己的代码中去实现:
我这里用的Tmvp框架 所以直接就在这写了
public class HomePageActivity extends BaseActivity<MyModel, MyPresenter> {
@BindView(R.id.tabBar)
JPTabBar tabBar;
@BindView(R.id.pager)
ViewPager pager;
ArrayList<Fragment> fragments;
// 这个集合可以不写 我的适配器有所以传了一个空集合
ArrayList<String> title;
@Titles
private static final String[] mTitles = {"首页", "美女", "视频", "我的"};
@SeleIcons
private static final int[] mSeleIcons = {R.drawable.ic_home_selected, R.drawable.ic_girl_selected, R.drawable.ic_video_selected, R.drawable.ic_care_selected};
@NorIcons
private static final int[] mNormalIcons = {R.drawable.ic_home_normal, R.drawable.ic_girl_normal, R.drawable.ic_video_normal, R.drawable.ic_care_normal};
@Override
protected void initView() {
ButterKnife.bind(this);
//初始化沉浸式状态栏
with = ImmersionBar.with(this);
fragments = new ArrayList<>();
title=new ArrayList<>();
try {
fragments.add(HomeFragment.class.newInstance());
fragments.add(GirlFragment.class.newInstance());
fragments.add(VideoFragment.class.newInstance());
fragments.add(MineFragment.class.newInstance());
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
tabBar.setContainer(pager);
MyadapterVideoFragment myadapterVideoFragment = new MyadapterVideoFragment(getSupportFragmentManager(),fragments,title);
pager.setAdapter(myadapterVideoFragment);
}
@Override
protected int getLayoutId() {
return R.layout.activity_home_page;
}
}
这样 底部导航栏就可以简单的实现了。