Android中的底部导航栏切换TabContainerView

前言:在GitHub上看到一个框架,实现底部导航栏切换,感觉不错,就在这里总结一下。

参考:https://www.jianshu.com/p/9aaff43bbf9f

           https://github.com/chenpengfei88/TabContainerView

第一步:准备工作。

在project的build.gradle中添加:

allprojects {
   	repositories {
   		...
   		maven { url 'https://jitpack.io' }
   	}
   }

在module的build.gradle中添加依赖:

implementation 'com.github.chenpengfei88:TabContainerView:v2.1'

第二步:实现步骤。

1. 布局:

    <!--
        divideLineColor表示上面分割线的颜色
        divideLineHeight表示上面分割线的宽度
    -->
    <com.fe.library.TabContainerView
        app:divideLineColor="#afd"
        app:divideLineHeight="2"
        android:id="@+id/tab_containerview_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </com.fe.library.TabContainerView>

2. Activity:

TabContainerView tabContainerView = (TabContainerView) findViewById(R.id.tab_containerview_main);
        Fragment[] fragments = new Fragment[] {new MainFragment(), new WorkFragment(), new AppFragment(), new MineFragment(), new MineFragment()};
        int[] iconImageArray = new int[]{R.mipmap.icon_tab_home, R.mipmap.icon_tab_store, R.mipmap.icon_tab_flypig, R.mipmap.icon_tab_record, R.mipmap.icon_tab_personal};
        int[] selectedIconImageArray = new int[]{R.mipmap.icon_tab_home_pre, R.mipmap.icon_tab_store_pre, R.mipmap.icon_tab_flypig_pre, R.mipmap.icon_tab_record_pre, R.mipmap.icon_tab_personal_pre};
        String[] nameArray=new String[]{"哈哈","呵呵","嘻嘻","啦啦","咳咳"};
        /**
         * 上下文
         *  Fragment数组
         *  Fragment管理器
         *  文本数组
         *  文本选中时的颜色
         *  图片默认数组
         *  图片选中时的数组
         */
        tabContainerView.setAdapter(new DefaultAdapter(this, fragments, getSupportFragmentManager(),nameArray,
                getResources().getColor(R.color.colorPrimary), iconImageArray, selectedIconImageArray));
        //设置当前选中的item
        tabContainerView.setCurrentItem(1);
        //设置当前有消息提示的item,提示小圆点
        tabContainerView.setCurrentMessageItem(1);
        //设置当前有消息提示的item,提示小圆点,小圆点有消息数量
        tabContainerView.setCurrentMessageItem(1, 3);
        //设置tabHost背景颜色
        tabContainerView.setTabHostBgColor(R.color.colorPrimaryDark);
        //tab切换监听
        tabContainerView.setOnTabSelectedListener(new OnTabSelectedListener() {
            @Override
            public void onTabSelected(AbsTab absTab) {

            }
        });

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值