底部导航菜单和顶部滑动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 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();
            }
        });
    }
}

效果:

底部导航菜单和顶部滑动tab_第1张图片

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

你可能感兴趣的:(Android移动开发)