set Enabled View With Alpha - Android User Interface

Android examples for User Interface:View Enable

Description

set Enabled View With 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 setEnabledViewWithAlpha(View view, Boolean isEnabled) {
        float alpha = isEnabled ? 1.0f : 0.5f;
        view.setEnabled(isEnabled);//from  w w w  .ja v a  2 s.c  o  m
        setAlpha(view, alpha);
    }

    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);
                animation.setDuration(0);
                animation.setFillAfter(true);
                view.startAnimation(animation);
            } else
                view.setAlpha(alpha);
        } else {
            view.setVisibility(View.GONE);
        }
    }
}

Related Tutorials