18

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

Streetboy
  • 4,351
  • 12
  • 56
  • 101
  • 2
    There are a lot of similar questions here. Use search. http://stackoverflow.com/questions/4813995/set-alpha-opacity-of-layout/4814651#4814651 – Alex Orlov May 14 '12 at 06:40

1 Answers1

39

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);
}
bob
  • 688
  • 8
  • 15