Java tutorial
//package com.java2s; //License from project: Open Source License import android.graphics.Color; public class Main { /** * Method returning color with modified alpha proportional to given values. * * @param color color to modify * @param fullValue total value * @param partValue part of fullValue. When partValue equals fullValue, the alpha is 255. * @return color with alpha relative to partValue/fullValue ratio. */ public static int getColorWithProportionalAlpha(int color, float fullValue, float partValue) { float progress = Math.min(Math.max(partValue, 0), fullValue) / fullValue; return Color.argb(Math.round(Color.alpha(color) * progress), Color.red(color), Color.green(color), Color.blue(color)); } }