Android Dialog - Rounded Corners and Transparency Android Dialog - Rounded Corners and Transparency android android

Android Dialog - Rounded Corners and Transparency


The only solution I have found is here. Use Dialog instead of AlertDialog and set transparent background:
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
Therefore you can't use the builder. But you can use new Dialog() also in onCreateDialog callback of DialogFragment if you follow to best guidelines.

This works also for Gingerbread.

Besides the layered drawable can be simplified to one shape with xml element <stroke> for the border.


I had similar issue when made dialog extending DialogFragment and to fix this used:

dialog.setStyle(DialogFragment.STYLE_NO_FRAME, 0);

Like this:

public class ConfirmBDialog extends DialogFragment {public static ConfirmBDialog newInstance() {    ConfirmBDialog dialog = new ConfirmBDialog();    Bundle bundle = new Bundle();    dialog.setArguments(bundle);    return dialog;}@Overridepublic void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    // This removes black background below corners.    setStyle(DialogFragment.STYLE_NO_FRAME, 0);}@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {    View view = inflater.inflate(R.layout.confirm_dialog, container, true);    getDialog().setCanceledOnTouchOutside(true);    return view;}

Hope this helps.


Just try

myDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));