Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zcweng/SwitchButton
SwitchButton.An beautiful+lightweight+custom-style-easy switch widget for Android,minSdkVersion >= 11
https://github.com/zcweng/SwitchButton
Last synced: about 1 month ago
JSON representation
SwitchButton.An beautiful+lightweight+custom-style-easy switch widget for Android,minSdkVersion >= 11
- Host: GitHub
- URL: https://github.com/zcweng/SwitchButton
- Owner: zcweng
- License: mit
- Created: 2016-12-23T13:09:26.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-01-12T02:57:56.000Z (11 months ago)
- Last Synced: 2024-10-29T17:41:29.599Z (about 1 month ago)
- Language: Kotlin
- Homepage: https://github.com/zcweng/SwitchButton
- Size: 1.77 MB
- Stars: 2,675
- Watchers: 43
- Forks: 415
- Open Issues: 39
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
- awesome-github-android-ui - SwitchButton - 优美的轻量级自定义样式的Switch按钮 (SwitchButton)
- awesome-list - zcweng/SwitchButton - SwitchButton.An beautiful+lightweight+custom-style-easy switch widget for Android,minSdkVersion >= 11 (Kotlin)
README
# SwitchButton
SwitchButton.An *beautiful+lightweight+custom-style-easy* switch widget for Android,minSdkVersion >= 14
issues welcome~
![](21879.gif)Features
-------
-depend without third-part library
-without raw files(pictures/drawables etc...), only one java and style.xml file
-drag switch supportedUseAge
-------
gradle:
```grovvy
repositories {
mavenCentral()
jcenter()
}...
dependencies {
implementation 'com.github.zcweng:switch-button:0.0.3@aar'
}
```layout.xml:
```xml
```
Java:
```java
SwitchButton switchButton = (com.suke.widget.SwitchButton)
findViewById(R.id.switch_button);switchButton.setChecked(true);
switchButton.isChecked();
switchButton.toggle(); //switch state
switchButton.toggle(false);//switch without animation
switchButton.setShadowEffect(true);//disable shadow effect
switchButton.setEnabled(false);//disable button
switchButton.setEnableEffect(false);//disable the switch animation
switchButton.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(SwitchButton view, boolean isChecked) {
//TODO do your job
}
});```
Kotlin:
```kotlin
val switchButton = findViewById(R.id.switch_button) as SwitchButtonswitchButton.isChecked = true
switchButton.isChecked
switchButton.toggle() //switch state
switchButton.toggle(false) //switch without animation
switchButton.setShadowEffect(true) //disable shadow effect
switchButton.isEnabled = false //disable button
switchButton.setEnableEffect(false) //disable the switch animation
switchButton.setOnCheckedChangeListener(object : SwitchButton.OnCheckedChangeListener {
override fun onCheckedChanged(view: SwitchButton?, isChecked: Boolean) {
//TODO do your job
}
})```
More Style:
```xml
阴影半径
阴影偏移
阴影颜色
关闭颜色
开启颜色
边框宽度
开启指示器颜色
开启指示器线宽
关闭指示器颜色
关闭指示器线宽
关闭指示器半径
是否选中
是否启用阴影
动画时间,默认300ms
按钮颜色
是否显示指示器,默认true:显示
背景色,默认白色
是否启用特效,默认true
```ScreenShot
-------
Sample Apk:
![](http://qr.api.cli.im/qr?data=https%253A%252F%252Fgithub.com%252Fzcweng%252FSwitchButton%252Fblob%252Fmaster%252Fsample%252Fsample-debug.apk&level=H&transparent=false&bgcolor=%23ffffff&forecolor=%23000000&blockpixel=12&marginblock=1&logourl=&size=280&kid=cliim&key=8144f9f150d38d7d364c923d0b9c87cf)License
-------
MIT, See the [LICENSE] file for details.