compile 'com.flyco.tablayout:FlycoTabLayout_Lib:2.0.8@aar'//底部导航
<com.flyco.tablayout.CommonTabLayout android:layout_height="100dp"
android:layout_width="match_parent"
android:id="@+id/tab_layout"
android:padding="5dp"
android:layout_alignParentBottom="true"/>
private String[] mTitles = {"首页", "美女", "视频", "关注"};
private int[] mIconUnselectIds = {
R.mipmap.ic_home_normal, R.mipmap.ic_girl_normal, R.mipmap.ic_video_normal, R.mipmap.ic_care_normal};
private int[] mIconSelectIds = {
R.mipmap.ic_home_selected, R.mipmap.ic_girl_selected, R.mipmap.ic_video_selected, R.mipmap.ic_care_selected};
private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
private int measuredHeight;
//屏幕适配
tab_layout.measure(0,0);
measuredHeight = tab_layout.getMeasuredHeight();
initTab();
for (int i = 0; i < mTitles.length; i++) {
mTabEntities.add(new TabEntity(mTitles[i],mIconSelectIds[i],mIconUnselectIds[i]));
}
tab_layout.setTabData(mTabEntities);
implementation 'com.hjm:BottomTabBar:1.2.2'//底部导航
buttomTab的方法
bottom.init(getSupportFragmentManager())
.setImgSize(30, 30)
.setFontSize(10)
.setChangeColor(Color.RED, Color.DKGRAY)
.addTabItem("首页",R.mipmap.ic_home_selected,R.mipmap.ic_home_normal, HomeFragment.class)
.addTabItem("美女", R.mipmap.ic_girl_selected, R.mipmap.ic_girl_normal, GirlFragment.class)
.addTabItem("视频", R.mipmap.ic_video_selected, R.mipmap.ic_video_normal, VieoFragment.class)
.addTabItem("关注", R.mipmap.ic_care_selected,R.mipmap.ic_care_normal, GuanFragment.class)
.isShowDivider(false);
//JPTabBar 的github网址
https://github.com/peng8350/JPTabBar
implementation 'com.jpeng:JPTabBar:1.2.3'
如果想在中间设置图片突起的话,父布局必须得是相对布局和,帧布局,它的高度得定死
<com.jpeng.jptabbar.JPTabBar
android:id="@+id/tabBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
app:TabIconSize="20dp"
app:TabMiddleView="@layout/item" />
java代码,利用反射注解
@Titles
private static final String[] mTitles = {"页面一", "页面二", "页面三", "页面四"};
@SeleIcons
private static final int[] mSeleIcons = {R.mipmap.a, R.mipmap.b, R.mipmap.c, R.mipmap.d};
@NorIcons
private static final int[] mNormalIcons = {R.mipmap.aa, R.mipmap.bb, R.mipmap.cc, R.mipmap.dd};
//获取中间图片的id
View middleView = tabBar.getMiddleView();
ImageView imageView = middleView.findViewById(R.id.img);
//关联viewPager
tabBar.setContainer(viewPager);
<com.flyco.tablayout.CommonTabLayout android:layout_height="100dp"
android:layout_width="match_parent"
android:id="@+id/tab_layout"
android:padding="5dp"
android:layout_alignParentBottom="true"/>
private String[] mTitles = {"首页", "美女", "视频", "关注"};
private int[] mIconUnselectIds = {
R.mipmap.ic_home_normal, R.mipmap.ic_girl_normal, R.mipmap.ic_video_normal, R.mipmap.ic_care_normal};
private int[] mIconSelectIds = {
R.mipmap.ic_home_selected, R.mipmap.ic_girl_selected, R.mipmap.ic_video_selected, R.mipmap.ic_care_selected};
private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
private int measuredHeight;
//屏幕适配
tab_layout.measure(0,0);
measuredHeight = tab_layout.getMeasuredHeight();
initTab();
for (int i = 0; i < mTitles.length; i++) {
mTabEntities.add(new TabEntity(mTitles[i],mIconSelectIds[i],mIconUnselectIds[i]));
}
tab_layout.setTabData(mTabEntities);
implementation 'com.hjm:BottomTabBar:1.2.2'//底部导航
buttomTab的方法
bottom.init(getSupportFragmentManager())
.setImgSize(30, 30)
.setFontSize(10)
.setChangeColor(Color.RED, Color.DKGRAY)
.addTabItem("首页",R.mipmap.ic_home_selected,R.mipmap.ic_home_normal, HomeFragment.class)
.addTabItem("美女", R.mipmap.ic_girl_selected, R.mipmap.ic_girl_normal, GirlFragment.class)
.addTabItem("视频", R.mipmap.ic_video_selected, R.mipmap.ic_video_normal, VieoFragment.class)
.addTabItem("关注", R.mipmap.ic_care_selected,R.mipmap.ic_care_normal, GuanFragment.class)
.isShowDivider(false);
//JPTabBar 的github网址
https://github.com/peng8350/JPTabBar
implementation 'com.jpeng:JPTabBar:1.2.3'
如果想在中间设置图片突起的话,父布局必须得是相对布局和,帧布局,它的高度得定死
<com.jpeng.jptabbar.JPTabBar
android:id="@+id/tabBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
app:TabIconSize="20dp"
app:TabMiddleView="@layout/item" />
java代码,利用反射注解
@Titles
private static final String[] mTitles = {"页面一", "页面二", "页面三", "页面四"};
@SeleIcons
private static final int[] mSeleIcons = {R.mipmap.a, R.mipmap.b, R.mipmap.c, R.mipmap.d};
@NorIcons
private static final int[] mNormalIcons = {R.mipmap.aa, R.mipmap.bb, R.mipmap.cc, R.mipmap.dd};
//获取中间图片的id
View middleView = tabBar.getMiddleView();
ImageView imageView = middleView.findViewById(R.id.img);
//关联viewPager
tabBar.setContainer(viewPager);