转自:https://blog.youkuaiyun.com/millerkevin/article/details/76686962
代码实现如下:
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();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
变亮
dimBackground(0.5f,1.0f);
1
变暗
dimBackground(1.0f,0.5f);
本文介绍了一种在安卓应用中实现背景透明度平滑变化的方法,通过使用ValueAnimator,可以轻松地让应用背景从完全不透明过渡到半透明,反之亦然,为用户提供更佳的视觉体验。
366

被折叠的 条评论
为什么被折叠?



