Skip to content

Instantly share code, notes, and snippets.

@Bahaaib
Created August 27, 2017 22:47
Show Gist options
  • Select an option

  • Save Bahaaib/96091b1a1313995758a67824dcb2e43b to your computer and use it in GitHub Desktop.

Select an option

Save Bahaaib/96091b1a1313995758a67824dcb2e43b to your computer and use it in GitHub Desktop.
Customize thumb & track colors of Switchcompat
//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