iOS风格SwitchButton。 只涉及到一个类文件,异常容易集成进入你的项目。支持开关的"延时和回滚"操作。only one class file, very easy to integrate into your program. support the delay operation and rolling back action of the switch
Last updated Jun 23, 2026
684
Stars
187
Forks
3
Issues
0
Stars/day
Attention Score
86
Topics
Language breakdown
Java 100.0%
▸ Files
click to expand
README
SwitchView

Download
DemoApp.apkUsage
- add library
implementation 'com.github.iielse:switchbutton:1.0.5'
- xml
<com.github.iielse.switchbutton.SwitchView
android:layoutwidth="wrapcontent"
android:layoutheight="wrapcontent"/>
- activity
switchView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean isOpened = switchView.isOpened();
}
});
or

switchView.setOnStateChangedListener(new SwitchView.OnStateChangedListener() {
@Override
public void toggleToOn(SwitchView view) {
view.toggleSwitch(true); // or false
}
@Override public void toggleToOff(SwitchView view) { view.toggleSwitch(false); // or true } });
Attributes
| attr | description | |:---|:---| | hasShadow | 是否显示按钮阴影 | | primaryColor | 开启状态背景色 | | primaryColorDark| 开启状态按钮描边色 | | offColor | 关闭状态描边色 | | offColorDark | 关闭状态按钮描边色 | | shadowColor | 按钮阴影色 | | ratioAspect | 按钮宽高形状比率(0,1] 不推荐大幅度调整 | | isOpened | 初始化默认状态 |🔗 More in this category