Lightens a color by increasing its alpha channel value - Android Graphics

Android examples for Graphics:Color Filter

Description

Lightens a color by increasing its alpha channel value

Demo Code


import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;

public class Main{
    /**/*from  w w  w  .j  a va2  s  .c  o m*/
     * Lightens a color by increasing its alpha channel value
     *
     * @param context the current context
     * @param res     the color resource
     * @param alpha   the alpha to set
     * @return a color int
     */
    @ColorInt
    public static int increaseOpacity(Context context, @ColorRes int res,
            int alpha) {
        int c = resolveColor(res, context);
        return Color.argb(alpha, Color.red(c), Color.green(c),
                Color.blue(c));
    }
    /**
     * Resolves a color resource.
     *
     * @param color   the color resource
     * @param context the current context
     * @return a color int
     */
    public static @ColorInt int resolveColor(@ColorRes int color,
            Context context) {
        if (Build.VERSION.SDK_INT >= 23) {
            return context.getResources().getColor(color,
                    context.getTheme());
        } else {
            return context.getResources().getColor(color);
        }
    }
}

Related Tutorials