Giter Club home page Giter Club logo

awesomeswitch's Introduction

AwesomeSwitch Download

AwesomeSwitch is a replacement for the standard Switch(View) android offers, and it offers much more customization than the standard switch component.

gif of AwesomeSwitch in use

Adding to project

Gradle

Add below code to your root build.gradle file (if you have multiple modules and only one of them require AwesomeSwitch, add the jcenter() repository only in that module's build.gradle).

allprojects {
    repositories {
        jcenter()
    }
}

And add the following dependency code to your module's build.gradle file.

dependencies {
    implementation "ss.anoop:awesome-switch:${latest-version}"
}

AwesomeSWitch can be included in your layout xml like any other view. Below is a simple example

Usage

<ss.anoop.awesomeswitch.AwesomeSwitch
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:radius="12dp"
    app:checkedColor="#53e079"
    app:backgroundColor="#000"
    app:checkedBackgroundColor="#53e079"
/>

Customization

Table below descripes the properties available to customize the AwesomeSwitch

Property Name Format Description
radius dimension Defines the size of the circle in the AwesomeSwitch
checkedColor color defines the color of the circle when the switch is in checked (on) state. Default color is white. If checked and unchecked(off) have different colors, there will be color transition animation when states change
uncheckedColor color defines the color of the circle when the switch is in unchecked (off) state. Default color is white. If checked(on) and unchecked have different colors, there will be color transition animation when states change
backgroundColor color defines the color of the switch background shape. The same will be used for checked and unchecked state unless checkedBackgroundColor is mentioned
checkedBackgroundColor color defines the color of the switch background shape in checked(on) state.
innerPadding dimension defines the padding applied to the background shape, ie, the space between the circle and the background shape
isChecked boolean to set the state to checked(on) or unchecked(off) at the time of inflation. Default value of this field is false
animationDuration integer defines the duration of unchecked to checked or the opposite animation duration in milliseconds. By default it is 300 milliseconds

Change Listener

AwesomeSwitch offers an OnCheckedListener that informs when checked state is changed. The callback has a boolean field which indicates checked(on) state when value is true, false indicates unchecked(off) state.

awesomeSwitch.setOnCheckedListener { state -> processState(state) }

Find this library useful? ❤️

Support it by joining stargazers for this repository. ⭐

License

Copyright 2019 anoop44 (Anoop)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

awesomeswitch's People

Contributors

anoop44 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.