Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Implementation

Angad Singh edited this page Feb 22, 2018 · 1 revision
  1. Start by adding a Switch (eg. LabeledSwitch) in your xml layout as:

        <com.github.angads25.toggle.LabeledSwitch
            android:id="@+id/switch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            android:textSize="14sp"
            app:on="false"
            app:colorBorder="@color/colorAccent"/>
  2. To the reference of Switch in your Activity/Fragment class set a Toggle Event Handler to it as below:

        LabeledSwitch labeledSwitch = findViewById(R.id.switch);
        labeledSwitch.setOnToggledListener(new OnToggledListener() {
            @Override
            public void onSwitched(LabeledSwitch labeledSwitch, boolean isOn) {
                // Implement your switching logic here
            }
        });

    That's It. All your switching callbacks would be handled in onSwitched method, parameter isOn will provide the current state of the switch.

Clone this wiki locally