Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.os.Build;

import android.view.View;

import android.view.animation.AlphaAnimation;

public class Main {
    /**
     * Change opacity of a given view, with the alpha level given as parameter.
     * This method considers the environment version.
     *
     * @param view       View that will change its opacity
     * @param alphaLevel Alpha level representing the opacity, where 0.0 is completely transparent, and 1.0 is completely opaque
     */
    public static void setAlphaForAllVersions(View view, float alphaLevel) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            view.setAlpha(alphaLevel);
        } else {
            AlphaAnimation alpha = new AlphaAnimation(alphaLevel, alphaLevel);
            alpha.setDuration(0); // Make animation instant
            alpha.setFillAfter(true); // Tell it to persist after the animation ends
            view.startAnimation(alpha);
        }
    }
}