解决华为手机,popupWindow除外屏幕其他位置全部变暗

 public void showPopupWindow(View parent) {
        //加载布局
        layout = (LinearLayout) LayoutInflater.from(SouSuoActivity.this).inflate(
                R.layout.pinpai_popwindow, null);
        //找到布局的控件
        // 实例化popupWindow
        popupWindow = new PopupWindow(layout, 600, 700);
        //控制键盘是否可以获得焦点
        popupWindow.setFocusable(true);
        WindowManager manager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
        WindowManager.LayoutParams layoutParams = SouSuoActivity.this.getWindow().getAttributes();
        layoutParams.alpha = 0.5f; //0.0-1.0
       //多加这一句,问题就解决了!这句的官方文档解释是:让窗口背景后面的任何东西变暗
SouSuoActivity.this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); SouSuoActivity.this.getWindow().setAttributes(layoutParams); popupWindow.setBackgroundDrawable(new BitmapDrawable(null, "")); @SuppressWarnings("deprecation") //获取xoff int xpos = manager.getDefaultDisplay().getWidth() / 2 - popupWindow.getWidth() / 2; //xoff,yoff基于anchor的左下角进行偏移。 popupWindow.showAsDropDown(parent, xpos, 0); }); popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { // popupWindow隐藏时恢复屏幕正常透明度
        
                setBackgroundAlpha(1.0f);
                iv.setImageResource(R.mipmap.spinner_xia);
            }
        });
    }
    //此方法在activity中写入
    public void setBackgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams lp = this.getWindow()
                .getAttributes();
        lp.alpha = bgAlpha;
        this.getWindow().setAttributes(lp);
    }
如果是fragment中使用,在依附的activity写上 setBackgroundAlpha方法,在依附的acivity写代码
public static  SouSuoActivity activity;
activity=this;(加载完布局以后)
然后类调用里面的方法 
SouSuoActivity.activity.setBackgroundAlpha();


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值