Android AlertDialog with rounded corners: rectangle seen below corners

Posted by user1455909 on Stack Overflow See other posts from Stack Overflow or by user1455909
Published on 2013-02-28T19:29:39Z Indexed on 2013/06/25 10:22 UTC
Read the original article Hit count: 6902

Filed under:
|
|

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:

enter image description here

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!

© Stack Overflow or respective owner

Related posts about android

Related posts about alertdialog