changes the alpha of the background for the given view - Android User Interface

Android examples for User Interface:View Background

Description

changes the alpha of the background for the given view

Demo Code


//package com.java2s;

import android.view.View;

public class Main {
    /**/*  www.j a  v a2  s.  c om*/
     * changes the alpha of the background for the given view
     *
     * @param view      to apply the background with {@link View#setBackground(android.graphics.drawable.Drawable)}
     * @param alpha     between 0 and 1
     * @param baseColor the 100% visible color
     */
    public static void setBackgroundAlpha(final View view,
            final float alpha, final int baseColor) {
        int a = Math.min(255, Math.max(0, (int) (alpha * 255))) << 24;
        int rgb = 0x00ffffff & baseColor;
        view.setBackgroundColor(a + rgb);
    }
}

Related Tutorials