I want a Dialog
with rounded corners, but when the Dialog
is seen there's a rectangle below it that's seen below the corners, like this:
I build the dialog
using a custom 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();
}
}
The dialog layout (playdialog) has the following drawable as background:
<?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>
As I said, I set this drawable as background:
android:background="@drawable/dialog_background"
I don't want that rectangle to be seen. How can I do it??
In this post the user had the same problem. I tried to use the solution that worked for him but it didn't work for me. I modified my DialogFragment
like this:
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;
}
The result is exactly the same. How can I remove that rectangle?
Thanks!
You can simply use MaterialAlertDialogBuilder to create custom dialog with rounded corners. then create a Alert Dialog object in Java class like this : AlertDialog alertDialog = new MaterialAlertDialogBuilder(this,R. style.
There are three kinds of lists available with the AlertDialog APIs: A traditional single-choice list. A persistent single-choice list (radio buttons) A persistent multiple-choice list (checkboxes)
To display rounded corners for AlertDialog in Flutter, specify the shape property of AlertDialog with RoundedRectangleBorder object with border radius specified. An AlertDialog with rounded corners having a border radius of 30 is shown in the following screenshot.
If you only want to change text format, you can just override alertDialogTheme attribute to change the theme for the AlertDialog .
I was shocked when I occured the same problem, the solution is also a little weird. Create your own custom drawable for eg see below.
<?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>
Add the following lines to your dialog:
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// This is line that does all the magic
dialog.getWindow().setBackgroundDrawableResource(
R.drawable.dialog_rounded);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With