Add a polished, iOS-style toggle switch to an Android settings screen with a single Gradle dependency and no custom view code.
Customize a toggle switch color, corner radius, and animation speed to match an app design system using XML attributes.
Flip a toggle switch state in code without triggering the change listener, for example when syncing the UI from a saved user preference.
Add on/off text labels inside a toggle switch to make its current state clearer for users.
SwitchButton is an Android library that provides a customizable toggle switch widget. Android ships with its own switch component, but this library gives developers more control over the appearance and behavior than the built-in version offers. The result looks similar to the on/off toggle found in iOS settings screens: a rounded background that the thumb (the circular knob) slides across. Usage follows the same pattern as Android's built-in CheckBox. You can call setChecked to turn it on or off programmatically, and toggle to flip its current state. The library adds variants of those calls that skip the sliding animation when you want an instant change, and further variants that change the state without triggering the change listener, which is useful when you need to update the UI from code without causing the listener to fire again. Styling is controlled through XML attributes or Java code at runtime. You can set separate colors or drawables for the thumb and the background, adjust the margin between them, control corner radius, change animation speed, and add text labels that appear inside the switch to indicate the on and off states. A single kswTintColor attribute lets you apply one color and have all related colors generated automatically. Version 2.0.0 reworked how the widget measures its own size and renamed several attributes to make the meanings clearer, so existing users need to update their attribute names when upgrading. The library is added to an Android project by adding a single line to the Gradle build file. It is available from Maven Central. A demo app on Google Play shows the full range of styling options. The README is bilingual, with the technical migration notes written in both English and Chinese.
← kyleduo on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.