android可自定义下划线的TabLayout

效果图:

android可自定义下划线的TabLayout_第1张图片

android可自定义下划线的TabLayout_第2张图片


使用方法:

可设置等分

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下载地址

你可能感兴趣的:(Java编程语言,Android控件使用,Android编码,androidstudio,滑动效果)