您的位置:首页 > 运维架构

【关于适配】华为手机PopupWindow弹出时背景不变暗 或者 华为手机PopupWindow背景一闪一闪问题处理

2016-11-11 12:02 375 查看
前言:

项目开发中遇到关于PopupWindow适配性的问题,特别是在华为手机上显示就会出现类似的情况。

下面这段PopupWindow弹出时背景变暗效果的代码在网上随处可见:

private void setBackgroundAlpha(float bgAlpha){
WindowManager.LayoutParams layoutParams = MainActivity.this.getWindow().getAttributes();
layoutParams.alpha = bgAlpha; //0.0-1.0
MainActivity.this.getWindow().setAttributes(layoutParams);
}


解决方法:

在相关的PopupWindow方法中加入这个方法,问题完美解决。

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);//多加这一句,问题就解决了!这句的官方文档解释是:让窗口背景后面的任何东西变暗


private void setBackgroundAlpha(float bgAlpha){
WindowManager.LayoutParams layoutParams = MainActivity.this.getWindow().getAttributes();
layoutParams.alpha = bgAlpha; //0.0-1.0

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

MainActivity.this.getWindow().setAttributes(layoutParams);
}


“`
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: