List of usage examples for android.widget Switch getTrackDrawable
public Drawable getTrackDrawable()
From source file:com.owncloud.android.ui.ThemeableSwitchPreference.java
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN) private void findSwitch(ViewGroup viewGroup) { for (int i = 0; i < viewGroup.getChildCount(); i++) { View child = viewGroup.getChildAt(i); if (child instanceof Switch) { Switch switchView = (Switch) child; int color = ThemeUtils.primaryAccentColor(); int trackColor = Color.argb(77, Color.red(color), Color.green(color), Color.blue(color)); // setting the thumb color DrawableCompat.setTintList(switchView.getThumbDrawable(), new ColorStateList(new int[][] { new int[] { android.R.attr.state_checked }, new int[] {} }, new int[] { color, Color.WHITE })); // setting the track color DrawableCompat.setTintList(switchView.getTrackDrawable(), new ColorStateList(new int[][] { new int[] { android.R.attr.state_checked }, new int[] {} }, new int[] { trackColor, Color.parseColor("#4D000000") })); break; } else if (child instanceof ViewGroup) { findSwitch((ViewGroup) child); }//from w w w. j av a 2s.c o m } }