Last active
August 29, 2015 14:20
-
-
Save lomanyong/634d272629cc8cd4658c to your computer and use it in GitHub Desktop.
Android 类似 Dialog 的窗口渐变效果
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
/** | |
* 调整窗口的透明度 | |
* @param from>=0&&from<=1.0f | |
* @param to>=0&&to<=1.0f | |
* | |
* */ | |
private void dimBackground(final float from, final float to) { | |
final Window window = getWindow(); | |
ValueAnimator valueAnimator = ValueAnimator.ofFloat(from, to); | |
valueAnimator.setDuration(500); | |
valueAnimator.addUpdateListener(new AnimatorUpdateListener() { | |
@Override | |
public void onAnimationUpdate(ValueAnimator animation) { | |
WindowManager.LayoutParams params = window.getAttributes(); | |
params.alpha = (Float) animation.getAnimatedValue(); | |
window.setAttributes(params); | |
} | |
}); | |
valueAnimator.start(); | |
} | |
/** 窗口背景变暗*/ | |
dimBackground(1.0f,0.5f); | |
/** 窗口背景变亮*/ | |
dimBackground(0.5f,1.0f); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment