Java tutorial
//package com.java2s; //License from project: Apache License import android.content.res.ColorStateList; import android.graphics.Color; public class Main { public static ColorStateList wrapColor(int newPrimaryColor) { int[][] states = new int[][] { new int[] { -android.R.attr.state_enabled }, // disabled new int[] {} // enabled }; int[] colors = new int[] { adjustAlpha(newPrimaryColor, 0.4f), newPrimaryColor }; return new ColorStateList(states, colors); } public static int adjustAlpha(int color, @SuppressWarnings("SameParameterValue") float factor) { int alpha = Math.round(Color.alpha(color) * factor); int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); return Color.argb(alpha, red, green, blue); } }