set View Alpha - Android User Interface

Android examples for User Interface:View Alpha

Description

set View Alpha

Demo Code


//package com.java2s;

import android.os.Build;
import android.view.View;
import android.view.animation.AlphaAnimation;

public class Main {
    public static void setAlpha(View view, float alpha) {
        if (alpha != 0) {
            view.setVisibility(View.VISIBLE);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
                final AlphaAnimation animation = new AlphaAnimation(alpha,
                        alpha);/*from   ww  w  . j a  v  a2s.c  o  m*/
                animation.setDuration(0);
                animation.setFillAfter(true);
                view.startAnimation(animation);
            } else
                view.setAlpha(alpha);
        } else {
            view.setVisibility(View.GONE);
        }
    }
}

Related Tutorials