Color mixing in android

See ArgbEvaluator (since API 11) http://developer.android.com/reference/android/animation/ArgbEvaluator.html


An alternative answer:

You can mix the bits in the hexs:

public static int mixTwoColors( int color1, int color2, float amount )
{
    final byte ALPHA_CHANNEL = 24;
    final byte RED_CHANNEL   = 16;
    final byte GREEN_CHANNEL =  8;
    final byte BLUE_CHANNEL  =  0;

    final float inverseAmount = 1.0f - amount;

    int a = ((int)(((float)(color1 >> ALPHA_CHANNEL & 0xff )*amount) +
                   ((float)(color2 >> ALPHA_CHANNEL & 0xff )*inverseAmount))) & 0xff;
    int r = ((int)(((float)(color1 >> RED_CHANNEL & 0xff )*amount) +
                   ((float)(color2 >> RED_CHANNEL & 0xff )*inverseAmount))) & 0xff;
    int g = ((int)(((float)(color1 >> GREEN_CHANNEL & 0xff )*amount) +
                   ((float)(color2 >> GREEN_CHANNEL & 0xff )*inverseAmount))) & 0xff;
    int b = ((int)(((float)(color1 & 0xff )*amount) +
                   ((float)(color2 & 0xff )*inverseAmount))) & 0xff;

    return a << ALPHA_CHANNEL | r << RED_CHANNEL | g << GREEN_CHANNEL | b << BLUE_CHANNEL;
}

SlidingTabStrip has really useful method for blending colors, looks great when used with ViewPager:

private static int blendColors(int color1, int color2, float ratio) {
    final float inverseRation = 1f - ratio;
    float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
    float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
    float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
    return Color.rgb((int) r, (int) g, (int) b);
}

Since April 2015 you can use blendARGB method from v4 support library:

int resultColor = ColorUtils.blendARGB(color1, color2, 0.5F);

Ratio value has to be 0.5 to achive even mix.