效果图如下:
简单使用方式
SegmentControlView segmentControlView=findViewById(R.id.segmentControlView);
segmentControlView.setViewWidthPx(dp2px(80));
segmentControlView.setViewHeightPx(dp2px(30));
segmentControlView.initData(new String[]{"全选", "反选", "全清"});
segmentControlView.btnClick(0);
segmentControlView.setSegmentControlViewViewOnClickListener(new SegmentControlView.SegmentControlViewOnClickListener() {
@Override
public void onBtnClickReturn(int position) {
Toast.makeText(MainActivity.this,""+position,Toast.LENGTH_SHORT).show();
}
});
还可以自定义背景drawable 以及字号等属性
How to
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
扫描二维码关注公众号,回复:
2209352 查看本文章
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.yangfanCode:SegmentedControl:SegmentedControlV1.1'
}
如果导入报错添加下面dependency
compile('com.github.yangfanCode:SegmentedControl:SegmentedControlV1.1') {
exclude group: 'com.android.support'
}
github项目地址