Search code examples
androidandroid-themeandroid-dialogfragment

Dialog with rounded corner in android


I have gone through some solutions but none solve my issue.

I have created a custom DialogFragment. and root element of dialog is cardView. I set cardCornerRadius of cardView.

Then i try to set Transparent Dialog because background color is also showing with it.

then i try to set the dialog theme like

<style name="PauseDialog" parent="@style/Theme.AppCompat.Light.Dialog">
       <!-- TTheme.AppCompat.Translucent-->
        <item name="android:windowAnimationStyle">@style/PauseDialogAnimation</item>
        <!--<item name="android:windowBackground">@android:color/transparent</item>-->
        <item name="android:windowBackground">@color/transparent</item>
        <item name="android:colorBackgroundCacheHint">@android:color/transparent</item>


        <item name="android:windowFrame">@null</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowTitleStyle">@null</item>
        <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
        <item name="android:backgroundDimEnabled">false</item>
        <item name="android:background">@android:color/transparent</item>
    </style>

The background still remains there. And then I also tried

dialog.getWindow().setBackgroundDrawable(
                new ColorDrawable(Color.TRANSPARENT));

but still dialog have background associated with it.

Is there any work around. How could i get rid of it.

I have created a DialogFragment and in onCreateDialog

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(),
                R.style.PauseDialog);
        setStyle(DialogFragment.STYLE_NO_FRAME, R.style.PauseDialog);

enter image description here


Solution

  • If you want rounded corner you can try apply custom shape using xml to your custom dialog backgroud. Following code will help you out.

    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    
         <solid android:color="#FFFFFF" />
            <corners
                android:radius="10dp"/>
    
        </shape>
    

    You can remove cardview as top element because dialog has its on shadow and depth. Add this line before you set contentview to dialog

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