Google launcher-style implementation of switch (enable/disable) icon

Overview

Android-SwitchIcon

API

Google launcher-style implementation of switch (enable/disable) icon

image

Compatibility

This library is compatible from API 15 (Android 4.0.3).

Download

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Add the dependency

dependencies {
    implementation 'com.github.zagum:Android-SwitchIcon:1.4.0'
}

Usage

SwitchIconView extends from AppCompatImageView so you can set icon with app:srcCompat

Set any icon (vector or image) to SwitchIconView and enjoy switchable icon in your app :)

Use app:si_tint_color to set color to icon. Default color is black;

Use app:si_disabled_color to set color when icon disabled. Default color is equals with app:si_tint_color;

Use app:si_disabled_alpha to set alpha when icon disabled. Default alpha is .5;

Use app:si_no_dash if you don't want to draw dash, when icon disabled;

Use app:si_animation_duration if you want to change switching state animation duration;

Use app:si_enabled to set initial icon state;

Fully customized implementation:

    <com.github.zagum.switchicon.SwitchIconView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="8dp"
        app:si_animation_duration="500"
        app:si_disabled_alpha=".3"
        app:si_disabled_color="#b7b7b7"
        app:si_tint_color="#ff3c00"
        app:si_enabled="false"
        app:si_no_dash="true"
        app:srcCompat="@drawable/ic_cloud"/>

Public methods and fields:

  var isIconEnabled: Boolean

  fun setIconEnabled(enabled: Boolean, animate: Boolean = true)

  fun switchState(animate: Boolean = true)
  

See sample project for more information.

License

Copyright 2017 Evgenii Zagumennyi

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.
Comments
  • UnsupportedOperationException in some devices

    UnsupportedOperationException in some devices

    Fatal Exception: java.lang.UnsupportedOperationException
           at android.view.GLES20Canvas.clipPath(GLES20Canvas.java:413)
           at com.github.zagum.switchicon.SwitchIconView.onDraw(Unknown Source)
    

    it happens on some old devices

    opened by hoomanmmd 5
  • Android Studio Preview rendering: NullPointerException

    Android Studio Preview rendering: NullPointerException

    Hi, i'm getting the following android studio preview error:

    java.lang.NullPointerException
    	at sun.java2d.SunGraphics2D.getClipBounds(SunGraphics2D.java:1831)
    	at sun.java2d.SunGraphics2D.getClipBounds(SunGraphics2D.java:1818)
    	at com.android.layoutlib.bridge.impl.GcSnapshot.drawInLayer(GcSnapshot.java:623)
    	at com.android.layoutlib.bridge.impl.GcSnapshot.draw(GcSnapshot.java:583)
    	at android.graphics.Canvas_Delegate.draw(Canvas_Delegate.java:1032)
    	at android.graphics.Canvas_Delegate.native_drawPath(Canvas_Delegate.java:713)
    	at android.graphics.drawable.VectorDrawable_Delegate$VPathRenderer_Delegate.drawPath(VectorDrawable_Delegate.java:1200)
    	at android.graphics.drawable.VectorDrawable_Delegate$VPathRenderer_Delegate.drawGroupTree(VectorDrawable_Delegate.java:1121)
    	at android.graphics.drawable.VectorDrawable_Delegate$VPathRenderer_Delegate.draw(VectorDrawable_Delegate.java:1129)
    	at android.graphics.drawable.VectorDrawable_Delegate.nDraw(VectorDrawable_Delegate.java:156)
    	at android.graphics.drawable.VectorDrawable.nDraw(VectorDrawable.java)
    	at android.graphics.drawable.VectorDrawable.draw(VectorDrawable.java:307)
    	at android.widget.ImageView.onDraw(ImageView.java:1286)
    	at com.github.zagum.switchicon.SwitchIconView.onDraw_Original(SwitchIconView.java:211)
    	at com.github.zagum.switchicon.SwitchIconView.onDraw(SwitchIconView.java)
    	at android.view.View.draw(View.java:17068)
    	at android.view.View.draw(View.java:16976)
    	at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3764)
    	at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61)
    	at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
    	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
    	at android.view.View.draw(View.java:16974)
    	at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3764)
    	at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61)
    	at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
    	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
    	at android.view.View.draw(View.java:16974)
    	at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3764)
    	at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61)
    	at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
    	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
    	at android.view.View.draw(View.java:17071)
    	at android.view.View.draw(View.java:16976)
    	at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3764)
    	at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61)
    	at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
    	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
    	at android.view.View.draw(View.java:16974)
    	at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3764)
    	at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61)
    	at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
    	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
    	at android.view.View.draw(View.java:16974)
    	at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3764)
    	at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61)
    	at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
    	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
    	at android.view.View.draw(View.java:16974)
    	at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3764)
    	at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61)
    	at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
    	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
    	at android.view.View.draw(View.java:17071)
    	at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:394)
    	at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:505)
    	at com.android.layoutlib.bridge.BridgeRenderSession.render(BridgeRenderSession.java:87)
    	at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:154)
    	at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:136)
    	at com.android.tools.idea.rendering.RenderTask.lambda$renderInner$71(RenderTask.java:698)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    	at java.lang.Thread.run(Thread.java:745)
    
    
    opened by ryantanjunming 2
  • Created method, which check state of icon.

    Created method, which check state of icon.

    Method returns true if icon is enabled, otherwise false. Sometimes we need state for restoring the state of activity/fragment, show/hide other views if state is enabled/disabled.

    opened by milovan92 2
  • Kotlinize The Sample App and the Library

    Kotlinize The Sample App and the Library

    This PR adds Kotlin powerful features for the library and the sample APP, I did a simple work which is converting your existing code from Java to kotlin, I hope this is a Good PR.

    opened by Younes-Charfaoui 1
  • SwitchIconView.java:209

    SwitchIconView.java:209

    There is an ANR for Android 9.0

    java.lang.IllegalArgumentException Invalid Region.Op - only INTERSECT and DIFFERENCE are allowed

    android.graphics.Canvas.checkValidClipOp (Canvas.java:779) android.graphics.Canvas.clipPath (Canvas.java:1007) com.github.zagum.switchicon.SwitchIconView.onDraw (SwitchIconView.java:209) android.view.View.draw (View.java:20226) android.view.View.updateDisplayListIfDirty (View.java:19101) android.view.View.draw (View.java:19954) android.view.ViewGroup.drawChild (ViewGroup.java:4333) android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112) android.view.View.updateDisplayListIfDirty (View.java:19092) android.view.View.draw (View.java:19954) android.view.ViewGroup.drawChild (ViewGroup.java:4333) android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112) android.view.View.updateDisplayListIfDirty (View.java:19092) android.view.View.draw (View.java:19954) android.view.ViewGroup.drawChild (ViewGroup.java:4333) android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112) android.view.View.draw (View.java:20229) android.view.View.updateDisplayListIfDirty (View.java:19101) android.view.View.draw (View.java:19954) android.view.ViewGroup.drawChild (ViewGroup.java:4333) android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112) android.view.View.updateDisplayListIfDirty (View.java:19092) android.view.View.draw (View.java:19954) android.view.ViewGroup.drawChild (ViewGroup.java:4333) android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112) android.view.View.updateDisplayListIfDirty (View.java:19092) android.view.View.draw (View.java:19954) android.view.ViewGroup.drawChild (ViewGroup.java:4333) android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112) android.view.View.updateDisplayListIfDirty (View.java:19092) android.view.View.draw (View.java:19954) android.view.ViewGroup.drawChild (ViewGroup.java:4333) android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112) android.view.View.updateDisplayListIfDirty (View.java:19092) android.view.View.draw (View.java:19954) android.view.ViewGroup.drawChild (ViewGroup.java:4333) android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112) android.view.View.draw (View.java:20229) com.android.internal.policy.DecorView.draw (DecorView.java:792) android.view.View.updateDisplayListIfDirty (View.java:19101) android.view.ThreadedRenderer.updateViewTreeDisplayList (ThreadedRenderer.java:686) android.view.ThreadedRenderer.updateRootDisplayList (ThreadedRenderer.java:692) android.view.ThreadedRenderer.draw (ThreadedRenderer.java:801) android.view.ViewRootImpl.draw (ViewRootImpl.java:3332) android.view.ViewRootImpl.performDraw (ViewRootImpl.java:3129) android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2498) android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1473) android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:7215) android.view.Choreographer$CallbackRecord.run (Choreographer.java:1004) android.view.Choreographer.doCallbacks (Choreographer.java:816) android.view.Choreographer.doFrame (Choreographer.java:751) android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:990) android.os.Handler.handleCallback (Handler.java:873) android.os.Handler.dispatchMessage (Handler.java:99) android.os.Looper.loop (Looper.java:280) android.app.ActivityThread.main (ActivityThread.java:6710) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)

    opened by gameplanet 1
  • Android P deprecation, Invalid Region.Op

    Android P deprecation, Invalid Region.Op

    Library crashes on Android P:

    java.lang.IllegalArgumentException: Invalid Region.Op - only INTERSECT and DIFFERENCE are allowed
            at android.graphics.Canvas.checkValidClipOp(Canvas.java:779)
            at android.graphics.Canvas.clipPath(Canvas.java:1007)
            at com.github.zagum.switchicon.SwitchIconView.onDraw(SwitchIconView.java:211)
    

    https://developer.android.com/reference/android/graphics/Canvas#clipPath(android.graphics.Path,%20android.graphics.Region.Op)

    opened by alashow 1
  • Wrong R.styleable attribute used to initialise SwitchIconView.enabled

    Wrong R.styleable attribute used to initialise SwitchIconView.enabled

    In the SwitchIconView constructor, line 91 of SwitchIconView.java reads:

     enabled = array.getBoolean(R.styleable.SwitchIconView_si_disabled_alpha, true);
    

    Shouldn't that be R.styleable.si_enabled?

    opened by andymstone 1
Releases(1.4.0)
Owner
Zagumennyi Evgenii
Zagumennyi Evgenii
A lightweight iOS switch view style for Android

iOS-SwitchView A lightweight iOS switch view style for Android Usage Add SwitchView into xml layout <vn.luongvo.widget.iosswitchview.SwitchView an

Luong Vo (Lucas) 72 Nov 5, 2022
A cute widget of Switch Button for you to create beautiful and friendly UI.

SwitchButton To get a quick preview, you can get Demo apk in Google Play or Directly download. This project provides you a convenient way to use and c

kyleduo 4.6k Dec 31, 2022
⭐️ beautiful switch widget with sticky animation ⭐️

StickySwitch StickySwitch library for android this library is beautiful switch widget with sticky animation Requirements Android SDK 15+ Usage Add it

GwonHyeok 767 Dec 6, 2022
Bootstrap style widgets for Android, with Glyph Icons

Android-Bootstrap Android Bootstrap is an Android library which provides custom views styled according to the Twitter Bootstrap Specification. This al

Bearded Hen 7.3k Jan 3, 2023
Android library providing an implementation of the Material Design Floating Action Button Speed Dial.

Android library providing an implementation of the Material Design Floating Action Button Speed Dial.

Sanyam Mehta 6 Dec 24, 2022
AwesomeSwitch is a replacement for the standard Switch(View) android offers, and it offers much more customization than the standard switch component.

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

Anoop S S 29 Jun 2, 2022
Flexible switch is a responsive switch with some nice features which developers can use for making awesome switches on android platform.

flexible-switch It is a responsive switch in android, it can resize itself according to its size. It's recommended to use it with ConstraintLayout to

Coders Route 5 Dec 20, 2022
Force enable gesture for third-party launcher in MIUI.

Fuck MIUI Gesture English Brief Enable this module to allow setting system gesture as nagation when using third party launcher. Strong Mode: Force usi

null 15 Dec 25, 2022
A material Switch with icon animations and color transitions

Material Animated Switch A material Switch with icon animations and color transitions Sample video: Youtube Material Animated Switch video Sample app:

Adrián Lomas 1.2k Dec 29, 2022
Vbmeta Patcher is an Android app that toggles the disable flags of the vbmeta partitions.

Vbmeta Patcher Vbmeta Patcher is an Android app that toggles the disable flags of the vbmeta partitions. Usage If either vbmeta_a or vbmeta_b are unpa

Captain Trips 11 Oct 17, 2022
Pixel Launcher Mods a root app for Android 12+ that enables you to add a number of features to the stock Pixel Launcher

A root app that enables you to add a number of features to the stock Pixel Launcher, without needing Xposed

Kieron Quinn 430 Jan 2, 2023
Library to change Android launcher App Icon and App Name programmatically !

AppIconNameChanger Change Android App launcher Icon and App Name programmatically ! Download Demo APK from HERE Kindly use the following links to use

Prabhakar Thota 587 Dec 29, 2022
If you have trouble pinning your custom icon to Launcher dynamically, try this library

CustomIconHelperX If you have trouble pinning your custom icon to Launcher dynam

Valentine Liao 1 Jan 4, 2022
Let third-party launcher always get themed icon in MIUI (Maybe also works for other Android based OS).

English 简体中文 Introduction This module can let third party launcher always use icons with MIUI/Flyme Themes. It may also work with other custom Android

Strawing 5 Sep 18, 2022
A lightweight iOS switch view style for Android

iOS-SwitchView A lightweight iOS switch view style for Android Usage Add SwitchView into xml layout <vn.luongvo.widget.iosswitchview.SwitchView an

Luong Vo (Lucas) 72 Nov 5, 2022
Androidicons is a professional, handcrafted icon set with 250 icons in 14 different colors and 5 sizes, including an icon font and all sources.

Android Developer Icons Android Developer Icons is a custom icon set, created by Opoloo. Included are: 250 hand-crafted, pixel-perfect icons in 5 size

Opoloo 685 Nov 23, 2022
iOS style scroll wheel (style similar to UIPickerView)

WheelPicker iOS-style scroll wheel picker Read this in other languages: Feature Day / Night Mode Support Customizable style Support circular scro

Tian Yiyan 21 Dec 30, 2022
A cute widget of Switch Button for you to create beautiful and friendly UI.

SwitchButton To get a quick preview, you can get Demo apk in Google Play or Directly download. This project provides you a convenient way to use and c

kyleduo 4.6k Dec 31, 2022
⭐️ beautiful switch widget with sticky animation ⭐️

StickySwitch StickySwitch library for android this library is beautiful switch widget with sticky animation Requirements Android SDK 15+ Usage Add it

GwonHyeok 767 Dec 6, 2022
A simple and customizable two or three states Switch View

RMSwitch A simple View that works like a switch, but with more customizations. With the option to choose between two or three states. (from v1.1.0) **

Riccardo Moro 656 Dec 2, 2022