效果图如下:


简单使用方式
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:
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项目地址

本文介绍了如何在Android中创建一个模仿iOS的SegmentControlView,包括简单的使用步骤和如何自定义背景图及字号等属性。通过添加JitPack仓库和依赖,可以轻松集成到项目中。
1016

被折叠的 条评论
为什么被折叠?



