Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the transparency (alpha) of a view on pre-SDK-11 on Android?

Tags:

android

How can I change the transparency (alpha) of a view on pre-SDK-11 on Android?

Before you suggest using a background colour with some transparency, please note that this method does not include all elements in the view such as the text of a button or the child views of a view group.

like image 734
Gallal Avatar asked Jan 31 '12 22:01

Gallal


People also ask

How do I change transparency on Android?

setAlpha(51); Here you can set the opacity between 0 (fully transparent) to 255 (completely opaque). The 51 is exactly the 20% you want.

How do you set up Alpha?

To get α subtract your confidence level from 1. For example, if you want to be 95 percent confident that your analysis is correct, the alpha level would be 1 – . 95 = 5 percent, assuming you had a one tailed test. For two-tailed tests, divide the alpha level by 2.

What is Alpha attribute in Android?

"alpha" is used to specify the opacity for an image.


2 Answers

Try using an AlphaAnimation : http://developer.android.com/reference/android/view/animation/AlphaAnimation.html


/* Have to use animation in order to get card faded. */

AlphaAnimation alpha = new AlphaAnimation(0.7F, 0.7F);
alpha.setDuration(0); // Make animation instant
alpha.setFillAfter(true); // Tell it to persist after the animation ends
view.startAnimation(alpha);
like image 90
Grime Avatar answered Oct 08 '22 04:10

Grime


The ViewHelper of NineOldAndroids is what I use, it is a static helper class and a real gem! Many here recommend NineOldAndroids but I have seen no mention of the ViewHelper. It is really easy to use.

import com.nineoldandroids.view.ViewHelper;
...

ViewHelper.setAlpha(myView, .2f);

You can also use it to set other properties like x, y etc, very handy when setting up for animations or building your UI. Many thanks to Jake Wharton for sharing his work with the community!

like image 26
lejonl Avatar answered Oct 08 '22 06:10

lejonl