[android] How to make custom dialog with rounded corners in android

You need to do the following:

  • Create a background with rounded corners for the Dialog's background:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    
        <solid android:color="#fff" />
    
        <corners
            android:bottomLeftRadius="8dp"
            android:bottomRightRadius="8dp"
            android:topLeftRadius="8dp"
            android:topRightRadius="8dp" />
    
    </shape>
    
  • Now in your Dialog's XML file in the root layout use that background with required margin:

    android:layout_marginLeft="20dip"
    android:layout_marginRight="20dip"
    android:background="@drawable/dialog_background"
    
  • finally in the java part you need to do this:

    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(layoutResId);
    View v = getWindow().getDecorView();
    v.setBackgroundResource(android.R.color.transparent);
    

This works perfectly for me.