自定义圆角Dialog

只设置背景是无效的,借助CardView和Window来做

java代码

  private void showSetSuccessDialog() {
        if(mContext==null) return;
        final Dialog dialog = new Dialog(mContext);
        dialog.setContentView(R.layout.two_parent_set_success);
        //设置背景透明,不然会出现白色直角问题
        Window window = dialog.getWindow();
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        dialog.setCanceledOnTouchOutside(false);
        dialog.findViewById(R.id.re_i_know).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(dialog.isShowing()){dialog.dismiss();}
            }
        });
        dialog.show();
    }

build.gradle

 implementation 'com.android.support:cardview-v7:28.0.0'

xml布局文件




    
    
    
        
    


你可能感兴趣的:(ProjectProblems)