底部导航菜单和顶部滑动tab

插入资源引用

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.github.open-android:FragmentTabhostUtils:0.5.0'
    //稳定版(推荐)没特殊需求建议使用官方TabLayout控件
//    implementation 'com.gxz.pagerslidingtabstrip:library:1.3.1'
    implementation group: 'com.jpardogo.materialtabstrip', name: 'library', version: '1.1.1'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-vector-drawable:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

使用:


public class TabMainFragment extends FragmentActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_main);

        List<TabViewChild> tabViewChildList = new ArrayList<>();
        TabViewChild tabViewChild01 = new TabViewChild(R.drawable.ic_home_black_24dp, R.drawable.ic_home_black_24dp, "首页", SubOneActivity.newInstance("首页"));
        TabViewChild tabViewChild02 = new TabViewChild(R.drawable.ic_notifications_black_24dp, R.drawable.ic_notifications_black_24dp, "分类", TabBFragment.newInstance("分类"));
        TabViewChild tabViewChild03 = new TabViewChild(R.drawable.ic_dashboard_black_24dp, R.drawable.ic_dashboard_black_24dp, "资讯", TabCFragment.newInstance("资讯"));
        tabViewChildList.add(tabViewChild01);
        tabViewChildList.add(tabViewChild02);
        tabViewChildList.add(tabViewChild03);

        TabView tabView = (TabView) findViewById(R.id.tabView);
        tabView.setTabViewChild(tabViewChildList, getSupportFragmentManager());
        tabView.setOnTabChildClickListener(new TabView.OnTabChildClickListener() {
            @Override
            public void onTabChildClick(int position, ImageView currentImageIcon, TextView currentTextView) {
                Toast.makeText(getApplicationContext(), "position:" + position, Toast.LENGTH_SHORT).show();
            }
        });
    }
}

效果:

git路径:https://github.com/yichuancq/navigationapp

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值