android可自定义下划线的TabLayout
程序员文章站
2022-03-11 17:51:34
...
效果图:
使用方法:
可设置等分
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项目源码上一篇: css怎么实现不透明度渐变
下一篇: html怎么设置元素不可见
推荐阅读
-
android自定义带下划线EditText
-
Android 入门第十讲02-广播(广播概述,使用方法(系统广播,自定义广播,两个activity之间的交互和传值),EventBus使用方法,数据传递,线程切换,Android的系统广播大全)
-
Android实现带数字的圆形进度条(自定义进度条)
-
Android实现自定义加载框的代码示例
-
php生成Android客户端扫描可登录的二维码
-
Android自定义控件实现icon+文字的多种效果
-
Android自定义View Flyme6的Viewpager指示器
-
实例详解Android自定义ProgressDialog进度条对话框的实现
-
Android带圆形数字进度的自定义进度条示例
-
Android编程实现自定义系统菜单背景的方法