Created
January 6, 2014 21:48
-
-
Save mhemmings/8290388 to your computer and use it in GitHub Desktop.
An android method to set the opacity of a view while supporting API 1+.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is | |
* completely transparent and 1 means the view is completely opaque. | |
* | |
* @param alpha The opacity of the view. | |
* @param view The view to change. | |
* | |
*/ | |
@TargetApi(Build.VERSION_CODES.HONEYCOMB) | |
public void setOpacity(View view, float alpha) { | |
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { | |
view.setAlpha(alpha); | |
} else { | |
AlphaAnimation alphaAnim = new AlphaAnimation(alpha, alpha); | |
alphaAnim.setDuration(0); | |
alphaAnim.setFillAfter(true); | |
view.startAnimation(alphaAnim); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment