Custom Switches for Android
Android Library for Custom Switches.
gradle implementation 'com.github.angads25:toggle:1.1.0'
Start by adding a Switch (eg.
LabeledSwitch) in your xml layout as:
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
onSwitchedmethod, parameter
isOnwill provide the current state of the switch.
Copyright (C) 2018 Angad SinghLicensed 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.