rightgenius / SwitchButton

A cute widget of Switch Button for you to create beautiful and friendly UI.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SwitchButton

Android Arsenal

To get a quick preview, you can find the Demo in Google Play or My Blog.

This project provides you a convient way to customise a SwitchButton widget in Android. With just resources changed and attrs set, you can get a lifelike SwitchButton in Android 5.0, iOS 7/8, MIUI, or Flyme and so on.

What are you waiting for, come to enjoy this widget.


Using SwitchButton in your application

ADT

Clone the project and use the -adt part as library

Gradle

Add dependencies in build.gradle of your module

dependencies {
	compile 'com.kyleduo.switchbutton:library:1.2.9'
}

Demo

Default Style

default_style

Material Style

materialdesign_style

Demo apk:

demo_preview

easy_to_use


Usage

In xml layout file, you can configure the face of switch button using these attrs.

  • onDrawable: drawable of background for status ON
  • offDrawable: drawable of background for status OFF
  • thumbDrawable: drawable of thumb
  • thumb_margin: set inner margin between thumb and edges
  • thumb_marginLeft/Top/Bottom/Right: set margin for specific edge
  • thumb_width: set the width of thumb, probably used for gradient drawable
  • thumb_height: set the height of thumb
  • onColor: set the color of status ON, usd for flat version, the priority is below of onDrawable
  • offColor: like the onColor
  • thumbColor: like the onColor
  • thumbPressedColor: like the thumbColor, but for pressed status
  • animationVelocity: distance of animation per frame
  • radius: used for color version, radius of corner of background and thumb.
  • measureFactor: factor limit the minimum width equals almost (the height of thumb * measureFactor)
  • insetLeft: left size for shrinking (1.2)
  • insetRight: right size for shrinking (1.2)
  • insetTop: top size for shrinking (1.2)
  • insetBottom: bottom size for shrinking (1.2)

You can alse change the configuration of SwitchButton in code using class Configuration. The attributes in xml each has a setter and you can use them. Call method setConfiguration(Configuration conf); of SwitchButton after that.

License

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.

About

A cute widget of Switch Button for you to create beautiful and friendly UI.


Languages

Language:Java 100.0%