答案 0 :(得分:1)
首先,您需要在自定义对话框布局中添加一些透明背景。您需要做的第二件事是将对话框的背景设置为透明。默认情况下,每个对话框都有背景。即使您将布局设置为具有透明背景,它仍将显示为不透明(由于默认背景)。您可以使用
将其删除getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
编辑
这是您需要做的
答案 1 :(得分:1)
您可以使用此类。在Color.parseColor("#66F9B639")
public class LoadingDialog {
private static LoadingDialog instance;
private Dialog dialog;
public static LoadingDialog getInstance() {
if (instance == null) {
synchronized (LoadingDialog.class) {
if (instance == null) {
instance = new LoadingDialog();
}
}
}
return instance;
}
public void show(Context context) {
if (dialog != null && dialog.isShowing())
return;
dialog = new Dialog(context);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#6620314c")));
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_loading);
ViewGroup.LayoutParams params = dialog.getWindow().getAttributes();
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
dialog.getWindow().setLayout(params.width, params.height);
dialog.show();
}
public void dismiss() {
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
}
}
}
答案 2 :(得分:0)
您可以简单地创建自定义对话框类,并为您要实现的目的设置布局(或其他视图)的背景,android:background="#66F9B639"
针对您的情况。
这里是一个例子:
这将是您的对话框类(或类似的东西,仅是示例):
public class FullSizeImageDialog extends Dialog {
private ImageView imageView;
private ProgressBar fullImageProgreesBar;
private Context dialogContext;
public FullSizeImageDialog(@NonNull Context context) {
super(context);
setContentView(R.layout.full_size_image_dialog);
dialogContext = context;
imageView = findViewById(R.id.full_size_image);
fullImageProgreesBar = findViewById(R.id.fullImageProgreesBar);
}
}
这是对话框的布局(在我的情况下为R.id.full_size_image
)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#66F9B639">
<!--Place your views here-->
</android.support.constraint.ConstraintLayout>
当您想显示对话框时,这非常简单:
FullSizeImageDialog dialog = new FullSizeImageDialog ();
dialog.show();