AlertDialog弹出消息后,背景色透明,不影响Activity的事件触发

背景色透明:
//        背景色
        dialog.getWindow().setDimAmount(0f);
不抢占Activity焦点:
//      dialog不去抢占焦点
        dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
LayoutInflater inflater = LayoutInflater.from(HomeActivity.this);
        RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.news_layout_9, null);
        final AlertDialog.Builder builder = new AlertDialog.Builder(HomeActivity.this, R.style.dialogNoBg);
        //通过setView设置我们自己的布局
        builder.setView(layout);
        dialog = builder.create();
//        背景色
        dialog.getWindow().setDimAmount(0f);
//        宽高和位置      
        dialog.getWindow().setLayout(DensityUtil.dp2px(350), LinearLayout.LayoutParams.WRAP_CONTENT);
        dialog.getWindow().setGravity(Gravity.TOP);
//      dialog不去抢占焦点
        dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
//      HomeActivity.this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();
//        跳转到消息页面
        layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ******************************
                dialog.dismiss();

            }
        });

你可能感兴趣的:(Android)