public class ColorUtils { public static int resourceColorAlpha(Context context, @ColorRes int colorResource, @IntRange(from = 0, to = 255) int alphaDecimal) { int color = context.getResources().getColor(colorResource); int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); return Color.parseColor("#" + Integer.toHexString(Color.argb(alphaDecimal, red, green, blue))); } }
object ColorUtils { fun resourceColorAlpha(context: Context, @ColorRes colorResource: Int, @IntRange(from = 0, to = 255) alphaDecimal: Int): Int { val color = context.resources.getColor(colorResource) val red = Color.red(color) val green = Color.green(color) val blue = Color.blue(color) return Color.parseColor("#" + Integer.toHexString(Color.argb(alphaDecimal, red, green, blue))) } }