前言
在创建弹窗功能时,一般有需求将背景的window界面变暗.下面两组代码就实现了变暗与恢复的功能.
变暗
public void startDark(){ WindowManager.LayoutParams params= mActivity.getWindow().getAttributes(); params.alpha=0.7f; mActivity.getWindow().setAttributes(params); }
讲解一下:
1.首先我们需要获取activity的window的 WindowManager.LayoutParams ,所以关键代码是 getAttributes();
2.然后在配置透明度 params.alpha=0.7f;
3.最后设置回去
恢复
public void finishDark(){ WindowManager.LayoutParams params= mActivity.getWindow().getAttributes(); params.alpha=1f; mActivity.getWindow().setAttributes(params); }
本文来自博客园,作者:观心静 ,转载请注明原文链接:https://www.cnblogs.com/guanxinjing/p/10412281.html
本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。