Skip to content

An amazing android library which helps to implement your own custom-designed creative toggles inside the android apps.

License

Notifications You must be signed in to change notification settings

vishal-sehgal/lottie-toggles

Repository files navigation

Lottie Toggles for Android 🎚⨕

An amazing android library which helps to implement your own custom-designed creative toggles inside the android apps.

Version API

Say Thanks! Twitter URL GitHub followers Twitter Follow

Download and try out the sample app in your mobile 📲

Get it on Google Play

Show some 💙 and 🌟 the repo to support the project

GitHub stars GitHub forks GitHub watchers
GitHub followers Twitter Follow

Open Source Love License

Implementation 💻📲

-> LottieSwitch

Now we are going to add this type of toggle inside our android app which is basically called a switch but here it's getting lottiefied hence LottieSwitch.

Step 1: Add this library inside dependency{ } block in your app's level build.gradle file and Sync your project.

dependency {

implementation 'dev.vishalsehgal.android:lottie-toggles:1.0.0'

}

Step 2:

Now, add your switch's Lottie .json file under res/raw/day_nite_switch.json directory.

Step 3:

In your layout file, Add the LottieSwitch view and set the switch file from previous step by adding app:switch_lottieFile="@raw/day_night_switch" attribute to the view.

    <dev.vishalsehgal.lottietoggles.LottieSwitch
        android:id="@+id/my_switch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:switch_lottieFile="@raw/day_night_toggle" />

Step 4:

Now, of course you may want to listen when the switch toggles! You can simply attach a listener by calling setOnCheckedChangedListener{} on it and add your logic inside it.

findViewById<LottieSwitch>(R.id.lottie_switch).setOnCheckedChangedListener { toggleableView, isChecked ->

	    // Add your logic here when switch toggles.
	    // isChecked holds the value of current state of switch.
            Toast.makeText(this, isChecked.toString(), Toast.LENGTH_SHORT).show()
        }

Step 5:

Enjoy your brand new cool toggle.🥳

Customization and Attributes 🎨

Available custom attributes for LottieToggles.

Attribute Name Example Value Description
switch_lottieFile @raw/monster_toggle Sets the lottie file to the switch.
switch_toggleSpeed 2 Sets the speed of switching toggles. Default is 3.
switch_checked false/true Sets the default value for the switch.

How to Contribute 🛠

  1. Fork the project.
  2. Create your new feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added this cool feature/ Fixed something.')
  4. Push the branch to your remote repo. (git push origin my-new-feature)
  5. From there Create new Pull Request to the Lottie Toggles.

LICENSE 📜


Copyright (c) 2020 Vishal Sehgal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.