我想要一个Dialog
带圆角的,但是当Dialog
看到它时,它下面有一个矩形,它在角落下面可以看到,如下所示:
我dialog
使用自定义构建DialogFragment
:
public class MyDialogFragment extends DialogFragment{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.playdialog, null));
return builder.create();
}
}
对话框布局(playdialog)具有以下可绘制作为背景:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid
android:color="#AAAAAAAA" />
<stroke
android:width="2dp"
android:color="#FF000000" />
<corners android:radius="20dp" />
</shape>
正如我所说,我将此可绘制对象设置为背景:
android:background="@drawable/dialog_background"
我不想看到那个矩形。我该怎么做??
在这篇文章中,用户遇到了同样的问题。我尝试使用对他有用的解决方案,但对我不起作用。我DialogFragment
像这样修改了我的:
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.playdialog, null));
Dialog d = builder.create();
d.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
return d;
}
结果是完全一样的。如何删除该矩形?
谢谢!