Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set View alpha in lower Api than 11? [duplicate]

Tags:

android

I need to set alpha for a view. It is ImageButton and on Touch event i want to set alpha that i could see it was pressed. Maybe there some work around on this ? It don't suit me changing background color. Because my background is image and i wan't to change alpha of this image. Also i don't want to use selectors because my images are created dynamically.

Finally if there are no way to do this. So how i could catch exception that it setAlpha isn't supported for Api phone is using ?

Thanks

like image 954
Streetboy Avatar asked May 14 '12 05:05

Streetboy


Video Answer


1 Answers

I found this snippet of code some time ago. Maybe it will help?

if (Build.VERSION.SDK_INT < 11) {
        final AlphaAnimation animation = new AlphaAnimation(alpha, alpha);
        animation.setDuration(duration);
        animation.setFillAfter(true);
        view.startAnimation(animation);
    } else
        view.setAlpha(alpha);
}
like image 179
bob Avatar answered Oct 08 '22 03:10

bob