效果图。略。。。。别人发的效果图太多了,我就不发了
可以实现高仿微信底部效果。。等
导入依赖:
//JPTabBar
implementation 'com.jpeng:JPTabBar:1.0.4'
//BottomNavigationBar
implementation 'com.ashokvarma.android:bottom-navigation-bar:2.0.4'
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity">
<android.support.v4.view.ViewPager
android:id="@+id/vp"
android:layout_above="@+id/tabbar"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.jpeng.jptabbar.JPTabBar
android:id="@+id/tabbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#303030"
app:TabHeight="56dp"
app:TabAnimate="None"
app:BadgeDraggable="true"
app:BadgePadding="4dp"
app:BadgeMargin="5dp"
app:BadgeTextSize="10dp"
app:TabNormalColor="#fff"
app:TabSelectColor="#fff"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
主方法内容:
public class MainActivity extends BaseActivity {
//设置标题
@Titles
private static final String[] mTitles={"首页","充电","我的"};
//设置选中图标
@SeleIcons
private static final int[] mSelectIcons={R.mipmap.home_solid,R.mipmap.qrscan_solid,R.mipmap.user};
//设置未选中图标
@NorIcons
private static final int[] mNormalIcon={R.mipmap.home_line,R.mipmap.qrscan_line,R.mipmap.user_line};
private ViewPager mVp;
private JPTabBar mTabBar;
private List<Fragment> fragments;
private PagerFragmentAdapter adapter;
//初始化控件
@Override
protected void initView() {
mVp = (ViewPager) findViewById(R.id.vp);
mTabBar = (JPTabBar) findViewById(R.id.tabbar);
}
//初始化数据
@Override
protected void initData() {
//创建一个集合
fragments = new ArrayList<>();
try {
fragments.add(HomeFragment.class.newInstance());
fragments.add(ChargeFragment.class.newInstance());
fragments.add(MyFragment.class.newInstance());
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
mTabBar.setContainer(mVp);
//设置适配器
adapter = new PagerFragmentAdapter(getSupportFragmentManager(), fragments);
mVp.setAdapter(adapter);
}
//初始化视图
@Override
protected int createView() {
return R.layout.activity_main;
}
}
适配器:
public class PagerFragmentAdapter extends FragmentStatePagerAdapter {
private List<Fragment> list;
//重写
public PagerFragmentAdapter(FragmentManager fm,List<Fragment> fragments) {
super(fm);
this.list = fragments;
}
@Override
public Fragment getItem(int i) {
return list.get(i);
}
@Override
public int getCount() {
return list.size();
}
}
控件属性总结:
其中tabAnimation属性:
Scale 缩放
Alpha 透明
Flip 旋转(左右)
Rotate 旋转(上下)
Jump 跳跃
None 无