Android dialog 背景全透明

public class BuyerInfoDialog extends Dialog implements View.OnClickListener {
  
    public BuyerInfoDialog(@NonNull Context context) {
        this(context, 0);
    }

    public BuyerInfoDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_buyer_info);
        initView();
        Window window = this.getWindow();
        if (window != null) {
            //去除系统自带的margin
            window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            //设置dialog在界面中的属性
            window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
            //背景全透明
            window.setDimAmount(0f);
        }

    }
}
private BuyerInfoDialog buyerInfoDialog;
if (buyerInfoDialog == null) {
            buyerInfoDialog = new BuyerInfoDialog(getContext(), R.style.Dialog_style);
        }

    

你可能感兴趣的:(Android dialog 背景全透明)