Android Dialog无法去除遮罩

them样式


但是我现在要用代码实现,尝试了好多方法,activity的界面外的背景都是黑色的。

android:backgroundDimEnabled设置false背景是黑色

Android Dialog无法去除遮罩_第1张图片

后面用代码的方式解决了问题

dialog.getWindow().setDimAmount(0f);

解决方案

private void showDialog(){
        View contentView = View.inflate(this,R.layout.map_postion_item,null);
        CustomTextView tvJxName = (CustomTextView) contentView.findViewById(R.id.tv_jx_name);
        CustomTextView tvBranchAddr = (CustomTextView) contentView.findViewById(R.id.tv_branch_address);
        ImageView iv_call_phone = (ImageView) contentView.findViewById(R.id.iv_call_phone);
        iv_call_phone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.show(MapDetailsActivity.this,"拨打电话");
            }
        });
        if(mFlag.equals("1")) {
            tvJxName.setText(mJxSchoolDtl.getSName());
            tvBranchAddr.setText(sb != null ? sb.getAddr() : "");
        }else {
            tvJxName.setText(mJxSchoolDtl.getSName());
            tvBranchAddr.setText(mJxSchoolDtl.getAddr());
        }
        mDialog = getCommentDialog(contentView);
        mDialog.getWindow().setDimAmount(0f);//核心代码 解决了无法去除遮罩
        mDialog.show();
    }

    public Dialog getCommentDialog(View dialogview){
        final Dialog dialog = new Dialog(this, R.style.action_sheet);
        dialog.setContentView(dialogview);
        dialog.setCanceledOnTouchOutside(true);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        //window.setBackgroundDrawable(new ColorDrawable());//去除阴影
        lp.width = getScreenWidth();
        //lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE;
        lp.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;// 就是这个属性导致不能获取焦点,默认的是FLAG_NOT_FOCUSABLE,故名思义不能获取输入焦点,
        window.setGravity(Gravity.BOTTOM);
        return dialog;
    }

最后献上解决后效果图

Android Dialog无法去除遮罩_第2张图片

你可能感兴趣的:(Android)