This library is a custom Switch toggle widget inspired by this dribbble shot.
Add the JitPack repository in your build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
And add the dependencies
dependencies {
compile 'com.github.jtv7:GenderToggle:1.0'
}
Please see the sample app for a library usage example.
Add GenderToggle to your view hieararchy. Either programatically or using xml:
<com.jtv7.gendertogglelib.GenderToggle
android:id="@+id/genderToggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:gt_default_selection="male" />
Default selection can be set using:
<com.jtv7.gendertogglelib.GenderToggle
app:gt_default_selection="male|female" />
Enabling/disabling glow:
<com.jtv7.gendertogglelib.GenderToggle
app:gt_glow_enabled="true|false" />
Setting custom male color:
<com.jtv7.gendertogglelib.GenderToggle
app:gt_male_color="#00F8FC" />
Setting custom female color:
<com.jtv7.gendertogglelib.GenderToggle
app:gt_female_color="#FB4D7A" />
Can also be set with the following setter methods:
genderToggle.setChecked(GenderToggle.Checked.MALE); //Default selection
genderToggle.setGlowEnabled(true); //Glow enabled
genderToggle.setMaleColor(Color.parseColor("#00F8FC")); //Male color
genderToggle.setFemaleColor(Color.parseColor("#FB4D7A")); //Female color
Getting current checked state:
switch (genderToggle.getChecked()) {
case MALE:
//Male checked
break;
case FEMALE:
//Female checked
break;
}
Or
genderToggle.isChecked() //True = female, False = male
To listen for the check changed events use:
genderToggle.setCheckedChangeListener(this);
public interface GenderCheckedChangeListener {
void onCheckChanged(Checked current);
}
enum Checked { MALE, FEMALE }
This will force hardware acceleration for the drawing animations. This is useful on slower devices, but glow will not work with this enabled.
genderToggle.useHardwareAcceleration();
Copyright 2018 jtv7
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.