set color Transparency - Android Graphics

Android examples for Graphics:Color Alpha

Description

set color Transparency

Demo Code

/*******************************************************************************
 * Copyright (c) 2011 MadRobot.//from   w ww  . j a  v a 2s .  c  o m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *  Elton Kent - initial API and implementation
 ******************************************************************************/
//package com.java2s;

public class Main {
    /**
     * 
     * @param color
     *            argb value
     * @param level
     *            0(fully transparent) to 255(fully opaque)
     * @return
     */
    public static int setTransparency(int color, int level) {
        level = (level << 24);
        return (color & 0x00ffffff) | level;
    }

    public static void setTransparency(int[] color, int level) {
        level = level << 24;
        for (int i = 0; i < color.length; i++) {
            color[i] = (color[i] & 0x00ffffff) | level;
        }
    }
}

Related Tutorials