1. 程式人生 > >AlertDialog去掉白色背景

AlertDialog去掉白色背景

 Activity activity = BaseActivity.getCurrentActivity();
        View view = LayoutInflater.from(activity).inflate(R.layout.no_net_connected_layout, null);
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setView(view);
        final AlertDialog alertDialog = builder.show();
        alertDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);(新增這行程式碼即可
) view.findViewById(R.id.rl_no_net_connect_custom_dialog).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (alertDialog != null) { alertDialog.dismiss(); } } }); view.findViewById(R.id.tv_retry_no_net_connected_custom_dialog).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (alertDialog != null) { alertDialog.dismiss(); } } }); } });