PopupWindow.setOutsideTouchable()无效

在实现popupwindow显示及消失的功能时,功能代码如下:
if (mViewReleasePop == null) {
mViewReleasePop = LayoutInflater.from(mActivity).inflate(R.layout.layout_relaease_secret, null);
}
if (mReleasePopupWindow == null) {

        mReleasePopupWindow = new PopupWindow(mViewReleasePop, LinearLayout.LayoutParams.MATCH_PARENT
                , LinearLayout.LayoutParams.WRAP_CONTENT);
        mReleasePopupWindow.setFocusable(true);
        mReleasePopupWindow.setOutsideTouchable(true);

        mReleasePopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
                lp.alpha = 1.0f;
                mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                mActivity.getWindow().setAttributes(lp);
            }
        });
    }

    if (mReleasePopupWindow != null && mReleasePopupWindow.isShowing()) {
        return;
    }

    mReleasePopupWindow.setAnimationStyle(R.style.showPopupAnimation);
    mReleasePopupWindow.showAtLocation(mParentLinearl, Gravity.BOTTOM, 0, 0);

    WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
    lp.alpha = 0.3f;
    mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    mActivity.getWindow().setAttributes(lp);

功能测试时发现在6.0以上版本功能是正常,但是低于6.0的安卓手机上,点击外部不会消失,并且点击返回键的onKeyDown事件都被拦截掉了,对比之前写的功能正常的代码,发现少了一句代码,

        mReleasePopupWindow.setBackgroundDrawable();
        因为目前没有背景,就写成
        mReleasePopupWindow.setBackgroundDrawable(new PaintDrawable(Color.TRANSPARENT));

添加之后,在4.4,5.0,6.0机器上测试,功能都恢复了正常,特此记录。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值