Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static final int SWITCH_STATE_LIST_ALPHA = (int)(0.3f*255);
- public static ColorStateList buildSwitchCompatColorStateListFromResId(
- Context context, int activatedColorResId) {
- return buildSwitchCompatColorStateList(
- context, ContextCompat.getColor(context, activatedColorResId)
- );
- }
- public static ColorStateList buildSwitchCompatColorStateList(Context context, int activatedColor) {
- final int disabledColor = ContextCompat.getColor(context, R.color.grey_300);
- final int disabledColorAlpha = Color.argb(
- SWITCH_STATE_LIST_ALPHA,
- Color.red(disabledColor),
- Color.green(disabledColor),
- Color.blue(disabledColor)
- );
- final int[][] states = new int[][] {
- new int[] { -android.R.attr.state_enabled },
- new int[] { android.R.attr.state_checked },
- new int[0]
- };
- final int[] colors = new int[] { disabledColorAlpha, activatedColor, disabledColor };
- return new ColorStateList(states, colors);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement