Created
August 27, 2017 22:47
-
-
Save Bahaaib/96091b1a1313995758a67824dcb2e43b to your computer and use it in GitHub Desktop.
Customize thumb & track colors of Switchcompat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //To reverse the switch ENABLE/DISABLE Text color against the switch thumb color | |
| public static void setSwitchColor(SwitchCompat v) { | |
| // thumb regular color | |
| int thumbColor = Color.parseColor("#00E5FF"); | |
| // track regular color | |
| int trackColor = Color.parseColor("#00B8D4"); | |
| // setting the thumb color on action | |
| DrawableCompat.setTintList(v.getThumbDrawable(), new ColorStateList( | |
| new int[][]{ | |
| new int[]{android.R.attr.state_checked}, | |
| new int[]{} | |
| }, | |
| new int[]{ | |
| thumbColor, | |
| Color.parseColor("#C2185B") | |
| })); | |
| // setting the track color on action | |
| DrawableCompat.setTintList(v.getTrackDrawable(), new ColorStateList( | |
| new int[][]{ | |
| new int[]{android.R.attr.state_checked}, | |
| new int[]{} | |
| }, | |
| new int[]{ | |
| trackColor, | |
| Color.parseColor("#F06292") | |
| })); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment