⭐️ beautiful switch widget with sticky animation ⭐️

Overview

StickySwitch

License API Android Arsenal

StickySwitch library for android

this library is beautiful switch widget with sticky animation

Image of Preview

Requirements

  • Android SDK 15+

Usage

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.GwonHyeok:StickySwitch:0.0.16'
}

How to use this library

Add StickySwitch to your xml layout

<io.ghyeok.stickyswitch.widget.StickySwitch
        android:id="@+id/sticky_switch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        app:ss_animationDuration="600"
        app:ss_iconPadding="18dp"
        app:ss_iconSize="22dp"
        app:ss_leftIcon="@drawable/ic_male"
        app:ss_leftText="Male"
        app:ss_rightIcon="@drawable/ic_female"
        app:ss_rightText="Female"
        app:ss_selectedTextSize="14sp"
        app:ss_sliderBackgroundColor="@color/colorSliderBackground"
        app:ss_switchColor="@color/colorSwitchColor"
        app:ss_textColor="@color/colorTextColor"
        app:ss_textSize="12sp" 
        app:ss_animationType="line"/>

Available attributes

Name Type Description
ss_iconPadding dimension -
ss_iconSize dimension -
ss_leftIcon integer -
ss_leftText string -
ss_rightIcon integer -
ss_rightText string -
ss_selectedTextSize dimension -
ss_textSize dimension -
ss_switchColor color -
ss_sliderBackgroundColor color -
ss_textColor color -
ss_animationDuration integer -
ss_textVisibility enum -
ss_animationType enum line or curved

Status change notification

StickySwitch.Direction has two value (LEFT, RIGHT)

onSelectedChange method called when you touch the switch.

When the switch is moved to the right, the direction variable is StickySwitch.Direction.RIGHT

also switch is moved to the left, that variable is StickySwitch.Direction.LEFT

Java Code Example

// Set Selected Change Listener
StickySwitch stickySwitch = (StickySwitch) findViewById(R.id.sticky_switch);
stickySwitch.setOnSelectedChangeListener(new StickySwitch.OnSelectedChangeListener() {
    @Override
    public void onSelectedChange(@NotNull StickySwitch.Direction direction, @NotNull String text) {
        Log.d(TAG, "Now Selected : " + direction.name() + ", Current Text : " + text);
    }
});

Direction

Methods

fun setDirection(direction: Direction, isAnimate: Boolean = true, shouldTriggerSelected: Boolean = true)

if you want switch button direction to left

stickySwitch.setDirection(StickySwitch.Direction.LEFT);

if you want switch button direction to right without animation

stickySwitch.setDirection(StickySwitch.Direction.RIGHT, false);

if you want switch button direction to right with animation and prevent call selectedChangeListener

stickySwitch.setDirection(StickySwitch.Direction.RIGHT, false, false);

Get current Direction

stickySwitch.getDirection(); // StickySwitch.Direction.LEFT

Text

get current status text

stickySwitch.getText()

get specific status text

stickySwitch.getText(StickySwitch.Direction.LEFT) // Get leftText

set left or right text

stickySwitch.setLeftText("Left");
stickySwitch.setRightText("Right");

set text typeface

stickySwitch.setTypeFace(Typeface.DEFAULT_BOLD);

text visibility

stickySwitch.setTextVisibility(StickySwitch.TextVisibility.VISIBLE); // Visible Text
stickySwitch.setTextVisibility(StickySwitch.TextVisibility.INVISIBLE); // Invisible Text
stickySwitch.setTextVisibility(StickySwitch.TextVisibility.GONE); // GONE Text

Icon

set left icon with drawableRes

stickySwitch.setLeftIcon(R.mipmap.ic_launcher);

set left icon with drawable

Drawable drawable = getDrawable(R.mipmap.ic_launcher);
stickySwitch.setLeftIcon(drawable);

Color

set colors

// The color format must be (0xAARRGGBB)
stickySwitch.setSliderBackgroundColor(0xFF181821);
stickySwitch.setSwitchColor(0xFF2371FA);
stickySwitch.setTextColor(0xFFFFFFFF);

Animation

custom duration

// Animation duration to 1000ms (default duration is 600ms)
stickySwitch.setAnimationDuration(1000);

set different animation type

// Set animation type to curved (default is line)
stickySwitch.setAnimationType(StickySwitch.AnimationType.CURVED);

Reference

Talos Onboarding

License

MIT License

Copyright (c) 2017 GwonHyeok

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.
Comments
  • onSelectedChange called unneccessarily without clicking when switch direction is changed programatically from another screen

    onSelectedChange called unneccessarily without clicking when switch direction is changed programatically from another screen

    onSelectedChange method is called automatically when changing the direction of the switch programmatically, is there any method to change the switch direction without invoking setOnSelectedChangeListener

    opened by midhun-murali 6
  • Curved connection

    Curved connection

    It's a more natural way to animate connection between two circles. I used path that has a concave line at top and convex at the bottom. Also, I did Gradle and Support library upgrade and incremented lib version to 0.0.9 I hope that I followed your coding standards :).

    enhancement 
    opened by VladimirWrites 6
  • Enchancement, Animation and selected background size.

    Enchancement, Animation and selected background size.

    Can it be possible to add the same animation LINE without the fact that the circle reduce his size during animation. Juste have a circle that go left from right and right from left.

    Can we have the possibility to set the circle background dimension?

    Thanks for the lib she is great and sorry for low english skills :)

    PS: I will make a pull request this week if you want !

    opened by tjouin 4
  • Vector drawable support for devices < api 21

    Vector drawable support for devices < api 21

    Please implement a setRghtIcon(Drawable) method (so i can implement a bindingAdapter to solve the vector drawable issue)

    ~~or better yet support vector drawable as drawable resource Id in xml input by using ContextCompat.getDrawable(context, drawable_id)~~

    Update: ContextCompat.getDrawable in custom view class does not work for vector drawables

    bug 
    opened by kenshin171 4
  • Manifest Merger Failed

    Manifest Merger Failed

    after I implemented this library i recieved this error _

    ERROR: Manifest merger failed : Attribute [email protected] value=(false) from AndroidManifest.xml:12:9-36 is also present at [com.github.GwonHyeok:StickySwitch:0.0.15] AndroidManifest.xml:12:9-35 value=(true). Suggestion: add 'tools:replace="android:allowBackup"' to element at AndroidManifest.xml:10:5-29:19 to override.

    _ can you remove allowbackup attribute?

    enhancement 
    opened by yasinhajilou 3
  • height=wrap_content in constraintLayout = 0 height

    height=wrap_content in constraintLayout = 0 height

    Height is 0 when the example below is placed in a constraintLayout with android:height="wrap_content". Works as expected if parent layout is LinearLayout.

    I used the xml code from readme with no changes.

    <io.ghyeok.stickyswitch.widget.StickySwitch
            android:id="@+id/sticky_switch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            app:iconPadding="18dp"
            app:iconSize="22dp"
            app:leftIcon="@drawable/ic_male"
            app:leftText="Male"
            app:rightIcon="@drawable/ic_female"
            app:rightText="Female"
            app:selectedTextSize="14sp"
            app:sliderBackgroundColor="@color/colorSliderBackground"
            app:switchColor="@color/colorSwitchColor"
            app:textColor="@color/colorTextColor"
            app:textSize="12sp" />
    
    bug 
    opened by kenshin171 3
  • Please prefix attrs with component name

    Please prefix attrs with component name

    Please can you add a namespace to your attributes. app:textcolor is not unique and causes clashes with other components. eg app:sticky_textcolor

    I am currently getting clashes with https://github.com/mancj/MaterialSearchBar when compiling with the following error Error:(449) Attribute "textColor" already defined with incompatible format.

    I have posted the same issue against the other component.

    bug 
    opened by wezley98 3
  • java.lang.NullPointerException in fragment

    java.lang.NullPointerException in fragment

    Hi, i want to use that in fragment but in setOnSelectedChangeListener method give this error: java.lang.NullPointerException: Attempt to invoke virtual method 'void io.ghyeok.stickyswitch.widget.StickySwitch.setOnSelectedChangeListener(io.ghyeok.stickyswitch.widget.StickySwitch$OnSelectedChangeListener)' on a null object reference plz help to solve error thanks

    opened by MohammadAmin94 2
  • Sticky switch problem

    Sticky switch problem

    I copy and pasted the example below .

     <io.ghyeok.stickyswitch.widget.StickySwitch
            android:id="@+id/sticky_switch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:iconPadding="18dp"
            app:iconSize="22dp"
            app:leftIcon="@drawable/ic_male"
            app:leftText="Male"
            app:rightIcon="@drawable/ic_female"
            app:rightText="Female"
            app:selectedTextSize="14sp"
            app:sliderBackgroundColor="@color/colorSliderBackground"
            app:switchColor="@color/colorSwitchColor"
            app:textColor="@color/colorTextColor"
            app:textSize="12sp" />
    

    I have a Fragment contains a StickySwitch and a viewPager That let me slide between fragments but the problem is both are not the same width. 17343051_10206794118212090_8869343590093681844_n 17362850_10206794118452096_4568935870435814851_n

    You can mention the difference between two layouts is it a bug or should I add more parameters ?

    opened by Ajimi 2
  • setDirection doesn't work

    setDirection doesn't work

    Hi,

    Pretty nice lib. I try to use the setDirection to initialize the StickySwitch right but for me doesn't work. Do i have to do anything else? I use setDirectiom(StickySwitcj.Direction.RIGHT) inside onCreate to initialize it.

    Thanks

    opened by michaelprimez 2
  • The height and width are not adjusted.

    The height and width are not adjusted.

    Hello, I'm trying to adjust the height and width, but the view is cut off and it doesn't shrink. How do I adjust the height and width?

    안녕하세요. 높이와 너비를 조절하려고하는데 뷰가 잘리기만 하고 실제로는 줄어 들지 않습니다. 높이와 너비를 조절 하려면 어떻게 해야하나요?

    opened by KwonDoby 1
  • jcenter remove library cannot used

    jcenter remove library cannot used

    • What went wrong: Execution failed for task ':app:checkDebugDuplicateClasses'.

    Could not resolve all files for configuration ':app:debugRuntimeClasspath'. Could not find com.github.GwonHyeok:StickySwitch:0.0.16. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/github/GwonHyeok/StickySwitch/0.0.16/StickySwitch-0.0.16.pom - https://repo.maven.apache.org/maven2/com/github/GwonHyeok/StickySwitch/0.0.16/StickySwitch-0.0.16.pom Required by: project :app

    opened by andrewindayang 0
  • null cannot be cast to non-null

    null cannot be cast to non-null

    How can I solve this problem Caused by: java.lang.NullPointerException: null cannot be cast to non-null type io.ghyeok.stickyswitch.widget.StickySwitch

    opened by yousefl0 1
  • Error inflating class io.ghyeok.stickyswitch.widget.StickySwitch

    Error inflating class io.ghyeok.stickyswitch.widget.StickySwitch

    I'm trying to use a alertdialog from a layout containing the switch.

    I get the error: android.view.InflateException: Binary XML file line #39 in com.example.authenticatorapp:layout/layout_movimentacao_dialog: Binary XML file line #39 in com.example.authenticatorapp:layout/layout_movimentacao_dialog: Error inflating class io.ghyeok.stickyswitch.widget.StickySwitch

    Can anybody help please?

    xml code: <io.ghyeok.stickyswitch.widget.StickySwitch android:id="@+id/sticky_switch" android:layout_width="wrap_content" android:layout_height="wrap_content" app:ss_animationDuration="600" app:ss_animationType="line" app:ss_iconPadding="18dp" app:ss_iconSize="22dp" app:ss_selectedTextSize="14sp" app:ss_textSize="12sp" />

    Activity code: `private void openMovimentacaoDialog() { LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.layout_movimentacao_dialog, null);

        AlertDialog alertDialog = new AlertDialog.Builder(this)
                .setView(view)
                .create();
    
        alertDialog.show();
    }`
    
    opened by rrenanh 1
  • copy / paste does not work when you import the library

    copy / paste does not work when you import the library

    copy / paste does not work in that class when importing the library (import io.ghyeok.stickyswitch.widget.StickySwitch) but StickySwitch works fine. Why is this caused?

    opened by kksal55 1
  • SVG icons not working in SDK version 17

    SVG icons not working in SDK version 17

    Hi,

    thanks for this awesome switch. My app supports SDK versions up to version 17 and I use SVG icons for the sticky switch. So I've tested my app in a virtual device with SDK version 17 and the app crahses by inflating the layout with following exception exception.txt

    It seems that the sticky switch doesn't support SVGs in older versions. If I use PNG icons, the app doesn't crash.

    opened by khmegger 1
Releases(0.0.16)
Owner
GwonHyeok
Full Stack Developer 🥊
GwonHyeok
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
Google launcher-style implementation of switch (enable/disable) icon

Android-SwitchIcon Google launcher-style implementation of switch (enable/disable) icon Compatibility This library is compatible from API 15 (Android

Zagumennyi Evgenii 2.3k Dec 17, 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
Circle button widget for Android

DEPRECATED This library is deprecated and no new development is taking place. Consider using a FAB(Floating action button) instead. E.g. the Android D

Markus Hintersteiner 1.5k Dec 9, 2022
ToggleButton Widget For Android Dev

ToggleButton ToggleButton Widget For Android Developers @Deprecated !!!项目已经停止维护,新项目移至https://github.com/zcweng/SwitchButton !!! How To Use xml

suke 2.1k Dec 19, 2022
A widget you can slide it to open or close something

SlideSwitch About SlideSwitch A button that you can slide on or off How to import into your project Android Studio use gradle. Gradle dependency: Add

Quinn 539 Jul 12, 2022
A download button with pretty cool animation

ArrowDownloadButton A download button with pretty cool animation, this is an implemention of https://dribbble.com/shots/2012292-Download-Animation Enj

Rongchan Liu 966 Nov 29, 2022
A shopping cart button with a telescopic displacement rotation animation ...一个带伸缩位移旋转动画的购物车按钮

AnimShopButton A shopping cart button with a telescopic displacement rotation animation ... 一个仿饿了么 带伸缩位移旋转动画的购物车按钮 注意,本控件非继承自ViewGroup,而是纯自定义View,实现的仿

张旭童 1.3k Nov 10, 2022
A small android library for tagging views inside a ScrollView as "sticky" making them stick to the top of the scroll container until a new sticky view comes and takes it's place

StickyScrollViewItems StickyScrollViewItems is a ScrollView subclass that allowed you to mark items inside the ScrollView as sticky. The items marked

Emil Sjölander 1k Jan 7, 2023
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
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
:octocat: ≡ DirectSelect is a selection widget with an ethereal, full-screen modal popup displaying the available choices when the widget is interact with.

DIRECT SELECT [JAVA] Selection widget with an ethereal, full-screen modal popup displaying the available choices We specialize in the designing and co

Ramotion 536 Nov 22, 2022
:four_leaf_clover:A beautiful android tag group widget.

AndroidTagGroup The TagGroup is a special layout with a set of tags. You can use it to tag people, books or anything you want. Also you can contribute

Jun Gu 2.5k Jan 2, 2023
Combination of a beautiful clock with widget, alarm, stopwatch & timer, no ads

Simple Clock The app has multiple functions related to timing. At the clock you can enable displaying times from other timezones, or use the simple, b

Simple Mobile Tools 462 Dec 28, 2022
. Android library that integrate sticky section headers in your RecyclerView

recyclerview-stickyheaders Recyclerview-stickyheaders is an Android library that makes it easy to integrate section headers in your RecyclerView. Thes

null 968 Nov 10, 2022
ListView with blur/parallax/sticky capabilities

BlurStickyHeaderListView What is BlurStickyHeaderListView? It is a custom ListView with a header that displays pictures from an URL. It then adds a ni

null 129 Oct 26, 2022
[UNMAINTAINED] Sticky Headers decorator for Android's RecyclerView

This project is no longer being maintained sticky-headers-recyclerview This decorator allows you to easily create section headers for RecyclerViews us

timehop 3.7k Dec 31, 2022
Android ListView with sticky headers

DEPRECATED HeaderListView is deprecated. No new development will be taking place. Quickstart Import the HeaderListView module in your Android Studio p

Applidium 314 Nov 10, 2022
[UNMAINTAINED] Sticky Headers decorator for Android's RecyclerView

This project is no longer being maintained sticky-headers-recyclerview This decorator allows you to easily create section headers for RecyclerViews us

timehop 3.7k Jan 8, 2023