Skip to content

Instantly share code, notes, and snippets.

@lomanyong
Last active August 29, 2015 14:20
Show Gist options
  • Save lomanyong/634d272629cc8cd4658c to your computer and use it in GitHub Desktop.
Save lomanyong/634d272629cc8cd4658c to your computer and use it in GitHub Desktop.
Android 类似 Dialog 的窗口渐变效果
/**
* 调整窗口的透明度
* @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