Need help with Android-Toggle-Switch?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

BelkaLab
461 Stars 96 Forks MIT License 53 Commits 1 Opened issues

Description

A customizable extension to Android switches that supports many items.

Services available

!
?

Need anything else?

Contributors list

No Data

Android-Toggle-Switch

Deprecation notice: this library is no longer maintained. If you are currently using it, we reccomend switching to the fork by its original developer: https://github.com/llollox/Android-Toggle-Switch

Alt text Android Arsenal Alt text

A customizable extension of Android Switches that supports also more than 2 items.

Sample of libray

Installation

Gradle

Add Gradle dependency:

dependencies {
    compile 'us.belka:androidtoggleswitch:1.2.2'
}

Maven

  us.belka
  androidtoggleswitch
  1.2.2
  pom

Usage

2 Items


Sample of libray with 2 items

3 Items


Sample of libray with 3 items

N - Items support

This can be accomplished only programmatically.

XML

xml

JAVA code

java
ToggleSwitch toggleSwitch = (ToggleSwitch) findViewById(R.id.multiple_switches);
ArrayList labels = new ArrayList<>();
labels.add("AND");
labels.add("OR");
labels.add("XOR");
labels.add("NOT");
labels.add("OFF");
toggleSwitch.setLabels(labels);
Sample of libray with 3 items

NOTE: Providing a custom array of labels, the attributes textToggle[Left/Center/Right] will be ignored.

Multiple checked items support

                

NOTE: Please not that it's a different widget

MultipleToggleSwitch
instead of the previous
ToggleSwitch
.

Getters and Setters

Toggle Switch

  • int getCheckedTogglePosition()
    Returns the current checked position
int position = toggleSwitch.getCheckedTogglePosition();
  • void setCheckedTogglePosition(int position)
    Checks the position passed as argument
int position = 3;
toggleSwitch.setCheckedTogglePosition(position);

Multiple Toggle Switch

  • void setCheckedTogglePosition(int position)
    Checks the position passed as argument
int position = 3;
multipleToggleSwitch.setCheckedTogglePosition(position);
  • void setUncheckedTogglePosition(int position)
    Unchecks the position passed as argument
int position = 0;
multipleToggleSwitch.setUncheckedTogglePosition(position);
  • Set getCheckedTogglePositions()
    Returns the set of the current checked positions
Set checkedPositions = multipleToggleSwitch.getCheckedTogglePositions();

Listeners

toggleSwitch.setOnToggleSwitchChangeListener(new ToggleSwitch.OnToggleSwitchChangeListener(){

        @Override
        public void onToggleSwitchChangeListener(int position, boolean isChecked) {
            // Write your code ... 
        }
    });

Customization

Attributes

It is possible to customize the buttons applying the following options:

| Option Name | Format | Description | | ---------------- | ---------------------- | ----------------------------- | | android:textSize |

dimension
| Text size of each button | | custom:activeBgColor |
color
| Background color of the checked button | | custom:activeTextColor |
color
| Text color of the checked button | | custom:inactiveBgColor |
color
| Background color of the inactive buttons | | custom:inactiveTextColor |
color
| Text color of the inactive buttons | | custom:separatorColor |
color
| Color of the vertical separator between inactive buttons | | custom:toggleWidth |
dimension
| Width of each button | | custom:cornerRadius |
dimension
| Corner Radius in dp |

Example


Sample of libray with 3 items

Contributors

Lorenzo Rigato, Fabrizio Rizzonelli, Android Developer @Belka

License

Android-Toggle-Switch is Copyright (c) 2016 Belka, srl. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About Belka

Belka Logo

Belka is a Digital Agency specialized in design, mobile applications development and custom solutions. We love open source software! You can see our projects or look at our case studies.

Interested? Hire us to help build your next amazing project.

www.belka.us

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.