Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. private static final int SWITCH_STATE_LIST_ALPHA = (int)(0.3f*255);
  2.  
  3. public static ColorStateList buildSwitchCompatColorStateListFromResId(
  4. Context context, int activatedColorResId) {
  5. return buildSwitchCompatColorStateList(
  6. context, ContextCompat.getColor(context, activatedColorResId)
  7. );
  8. }
  9.  
  10. public static ColorStateList buildSwitchCompatColorStateList(Context context, int activatedColor) {
  11.  
  12. final int disabledColor = ContextCompat.getColor(context, R.color.grey_300);
  13. final int disabledColorAlpha = Color.argb(
  14. SWITCH_STATE_LIST_ALPHA,
  15. Color.red(disabledColor),
  16. Color.green(disabledColor),
  17. Color.blue(disabledColor)
  18. );
  19.  
  20. final int[][] states = new int[][] {
  21. new int[] { -android.R.attr.state_enabled },
  22. new int[] { android.R.attr.state_checked },
  23. new int[0]
  24. };
  25.  
  26. final int[] colors = new int[] { disabledColorAlpha, activatedColor, disabledColor };
  27.  
  28. return new ColorStateList(states, colors);
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement