Skip to content

sigma1326/NiceSwitch

Repository files navigation

Switcher (Java Version)

Original library is coded in kotlin by Alexander Kolpakov

sample

Created this cool switch animation from Oleg Frolov as an android library.

USAGE

Just add Switcher view in your layout XML and Switcher library in your project via Gradle:

allprojects {
    repositories {
    ...
    maven { url 'https://jitpack.io' }
    ...
  }
}
dependencies {
  implementation 'com.github.sigma1326:NiceSwitch:1.0'
}

XML

<com.sigma.niceswitch.NiceSwitch // or NiceSwitchRound
    android:id="@+id/switcher"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:switcher_on_color="@color/on_color"
    app:switcher_off_color="@color/off_color"
    app:switcher_icon_color="@color/icon_color" />

You must use the following properties in your XML to change your Switcher.

Properties:
  • android:checked (boolean) -> default true
  • app:switcher_on_color (color) -> default #48ea8b
  • app:switcher_off_color (color) -> default #ff4651
  • app:switcher_icon_color (color) -> default white

Java

 niceSwitch.setOnCheckedChangedListener(checked -> {
     if(checked) {
         action()
     }
 });