gpt4 book ai didi

带圆角的 Android AlertDialog : rectangle seen below corners

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:05:27 24 4
gpt4 key购买 nike

我想要一个带有圆角的 Dialog,但是当看到 Dialog 时,它下面有一个矩形,在圆角下方,如下所示:

enter image description here

我使用自定义 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"

我不想看到那个矩形。我该怎么做??

this发布用户有同样的问题。我尝试使用对他有用的解决方案,但对我不起作用。我像这样修改了我的 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;
}

结果完全一样。我怎样才能删除那个矩形?

谢谢!

最佳答案

当我遇到同样的问题时,我感到震惊,解决方案也有点奇怪。创建您自己的自定义可绘制对象,例如,请参见下文。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<solid android:color="@color/text_highlight" />

<stroke
android:width="5dp"
android:color="@color/text_highlight" />

<corners android:radius="12dp" />

<stroke
android:width="1dp"
android:color="@android:color/transparent" />

</shape>

将以下行添加到您的对话框中:

 dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

// This is line that does all the magic
dialog.getWindow().setBackgroundDrawableResource(
R.drawable.dialog_rounded);

关于带圆角的 Android AlertDialog : rectangle seen below corners,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15144033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com