To get a quick preview, you can find Demo apk in Google Play or Directly download.
This project provides you a convenient way to use and customise a SwitchButton widget in Android. With just resources changed and attrs set, you can create a lifelike SwitchButton of Android 5.0+, iOS, MIUI, or Flyme and so on.
Now we get the biggest movement since SwitchButton published. v1.3.0 comes with totally reconsitution and more convenient API. A wholly new demo can give you a tour in it.
- Fixed #89 .
- Fixed #65.
- Update text layout, tests looks like center.
- Fixed #64. Respect to clickable and focusable attributes.
- Support #49. By default SwitchButton found accentColor of your theme for tintColor. (accentColor is used for controls according to Material Design guideline. )
- fixed #49.
- Support operation without onCheckedChanged callback.
- Add text feature. You can set text for either checked or unchecked status with kswTextOn and kswTextOff attrs. And you can set the margin of text in horizontal direction using kswTextMarginH attr.
- For additional, you can set small icons now by using SpannableString with setText() method in code.
- Thanks @lpmfilho
- Fix #40
- Fix SwitchButtonMD style bug in RecyclerView and add page for test. *Fix bug in setCheckedImmediately() in onCheckedChanged() method. (setChecked in onChecked)
- setClickable(boolean) support.
- Bug fix.
- Remove shadow of MD style to support under 5.0.
- Reconstructe the whole library.
- More convenient customization way by tintColor.
- New design demo. All APIs in ONE. *Fix issue #23 #25 #26 *Just exciting!!!
- Fix issue #22 by change the attributes' name to prevent conflict;
- Fix issue #19.
- Fix stretch bug while using higher API. *Add Gradle support. *Built in Android Studio.
- Fix rendering bug on some devices. *Fix states bug.
- With calling the method setChecked(boolean, false);, you can change the status without invoking the listener.
- Fix shrink bug in Android 5.0 (the problem is same like it is in Android 4.4, which has been fixed in 1.2.4). *More available to setup Material Design style SwitchButton using @style/MD in xml layout. *Fix Demo Project bug
- fix shrink bug(that will cause the content out of bounds not disapper, on Android 4.4)
- upload .pad resource, whitch I forgot to upload before.(My fault.)
- bug fix
- upgrade demo apk
- more clear way to use
Since the animation ran on sub thread, "toggle" and "setChecked" methods may mot execute as you wish what cause the checked status change immediately.
This problem may be solved, but I declared 2 methods to deal with the situation whether you want it happen immediately.
If you want to set the checked status immediately, just call setChecked(boolean checked); method like CheckBox. And slideToChecked(boolean checked); method for slow one with slide animation.
When toggle, call toggle(); with change the status immediately and toggle(false); for slow one.
(11/08/2014)
- Add StateList support for all resources and enable/disable, pressed has been tested in Demo.
- New Style with Material Design, preview below.
- Add "shrink" feature. This makes you can draw your image resources out size the view bounds, in the other word, shrink the size of view and make the experience stay the same.
New Style with Material Design:
To use shrink feature, you can easily add these attributes in your xml file. It is recommended that set these values positive.
- insetLeft: left size for shrinking
- insetRight: right size for shrinking
- insetTop: top size for shrinking
- insetBottom: bottom size for shrinking
(10/08/2014)
- Fix lots of bugs.
- Change the default style
- Add iOS7 style, you can just use like how the demo did
- Update demo, it becomes more convenient, effective and beautiful
- Add new attribute: measureFactor, you can custom the factor between width and height now. It is convenient to config the rest space of background. Learn more in the demo.
- Update the logic of thumbMargin, it can work well with negative margins now (iOS style just using this trick).
new default style and demo apk looks like this:
Add an attr of radius, now you can change the radius when configure the button's face!