explaingit

kyleduo/switchbutton

4,746JavaAudience · developerComplexity · 2/5Setup · easy

TLDR

An Android library that adds a smooth, fully customizable toggle switch widget to your app, with more styling options than the built-in Android switch and an iOS-style rounded appearance.

Mindmap

mindmap
  root((switchbutton))
    What it does
      Custom toggle switch widget
      Android UI component
      More styling than built-in
    Styling options
      Thumb and background colors
      Corner radius control
      Animation speed
      On/off text labels
    Usage
      XML attribute styling
      Java runtime API
      Single Gradle dependency
    Audience
      Android developers
      App UI designers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add a polished, iOS-style toggle switch to an Android settings screen with a single Gradle dependency and no custom view code.

USE CASE 2

Customize a toggle switch color, corner radius, and animation speed to match an app design system using XML attributes.

USE CASE 3

Flip a toggle switch state in code without triggering the change listener, for example when syncing the UI from a saved user preference.

USE CASE 4

Add on/off text labels inside a toggle switch to make its current state clearer for users.

Tech stack

JavaAndroidGradle

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

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.

Copy-paste prompts

Prompt 1
Show me how to add SwitchButton to an Android project via Gradle and define a styled toggle in XML with a custom tint color and rounded corners.
Prompt 2
I am using SwitchButton in my Android app and need to update its checked state from code without triggering the OnCheckedChangeListener. What method do I call?
Prompt 3
How do I add ON and OFF text labels inside a SwitchButton widget, and which XML attributes control their text and appearance?
Prompt 4
I upgraded SwitchButton to version 2.0.0 and my XML attributes broke. Which attribute names changed and how do I migrate my existing layouts?
Open on GitHub → Explain another repo

← kyleduo on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.