欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

android可自定义下划线的TabLayout

程序员文章站 2022-03-11 17:51:34
...

效果图:

android可自定义下划线的TabLayout

android可自定义下划线的TabLayout


使用方法:

可设置等分

ModifyTabLayout tabLayout=findViewById(R.id.modiftTabLayout);
        ViewPager vp=findViewById(R.id.vp);
        tabLayout.setViewHeight(dp2px(35));
        tabLayout.setBottomLineWidth(dp2px(10));
        tabLayout.setBottomLineHeight(dp2px(3));
        tabLayout.setBottomLineHeightBgResId(R.color.color_14805E);
        tabLayout.setItemInnerPaddingLeft(dp2px(6));
        tabLayout.setItemInnerPaddingRight(dp2px(6));
        tabLayout.setmTextColorSelect(ContextCompat.getColor(this,R.color.color_14805E));
        tabLayout.setmTextColorUnSelect(ContextCompat.getColor(this,R.color.color_666666));
        tabLayout.setTextSize(16);
//        int width=getResources().getDisplayMetrics().widthPixels;
//        tabLayout.setNeedEqual(true,width);
        CustomFragmentPagerAdapter adapter = new CustomFragmentPagerAdapter(getSupportFragmentManager());
        adapter.addFrag(new TestFragment(), "巴西");
        adapter.addFrag(new TestFragment(), "西班牙");
        adapter.addFrag(new TestFragment(), "阿根廷");
        adapter.addFrag(new TestFragment(), "葡萄牙");
        adapter.addFrag(new TestFragment(), "俄罗斯");
        adapter.addFrag(new TestFragment(), "巴西");
        adapter.addFrag(new TestFragment(), "西班牙");
        adapter.addFrag(new TestFragment(), "阿根廷");
        adapter.addFrag(new TestFragment(), "葡萄牙");
        adapter.addFrag(new TestFragment(), "俄罗斯");
        vp.setAdapter(adapter);
        vp.setOffscreenPageLimit(adapter.getCount());
        tabLayout.setupWithViewPager(vp);

如果不需要配和viewPager使用的话直接调用

setTabData

方法添加数据即可

How to

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:



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










Step 2. Add the dependency



dependencies {
       implementation 'com.github.yangfanCode:ModifyTabLayout:ModifyTabLayoutV1.0'
}


如果报错使用下面的dependency

implementation ('com.github.yangfanCode:ModifyTabLayout:ModifyTabLayoutV1.0') {
        exclude group: 'com.android.support'
    }
github项目源码

CSDN下载地址