Android 让Dialog实现背景透明

1、实现自定义Dialog 布局 dialog_main_sign.xml





   

   


2、代码

    private ImageView img_sing_x;

    public void showDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(me.getContext());
        final AlertDialog dialog = builder.create();
        View dialogView = View.inflate(this.getContext(), R.layout.dialog_main_sign, null);
        dialog.setView(dialogView, 0, 0, 0, 0); // 去边距,兼容2.X
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        img_sing_x = (ImageView) dialogView.findViewById(R.id.img_sing_x); // guanbi

        dialogView.findViewById(R.id.img_sing_x).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();
    }

注意: dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
这才是实现背景透明的重点

你可能感兴趣的:(Android 让Dialog实现背景透明)