7

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

Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
  • maybe a stupid question, but just to get sure: When do you set backgroundDrawable of Your dialog? It´s important to set it BEFORE setContentView() and show().... – Opiatefuchs Mar 30 '16 at 12:42
  • try adding shape with rounded corners as background – Vivek Mishra Mar 30 '16 at 12:44
  • Already tried this Vivek Mishra http://stackoverflow.com/questions/28937106/how-to-make-custom-dialog-with-rounded-corners-in-android – Zar E Ahmer Mar 30 '16 at 12:48
  • please check for edit of my answer. A tutorial is provided, you can follow that. – Android Geek Mar 31 '16 at 05:11
  • Possible duplicate of [How to make custom dialog with rounded corners in android](https://stackoverflow.com/questions/28937106/how-to-make-custom-dialog-with-rounded-corners-in-android) – DarkCygnus Jun 15 '18 at 21:08

4 Answers4

13

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));
Harshal Bhatt
  • 731
  • 10
  • 25
0

Try use in parent style a no title bar theme and make it translucent:

<style name="PauseDialog" parent="@android:style/Theme.NoTitleBar">
  ....rest of your style
 <item name="android:windowContentOverlay">@null</item>
 <item name="android:windowIsTranslucent">true</item>
 <item name="android:windowBackground">@android:color/transparent</item>
 <item name="android:windowNoTitle">true</item>      
 <item name="android:backgroundDimEnabled">false</item>
</style>
rcorbellini
  • 1,307
  • 1
  • 21
  • 42
0

I arrived late but with the solution to your question. just use the android:dialogCornerRadius in your style file.

Use it like this in your values/styles:

<item name="android:dialogCornerRadius">20dp</item>
        
Dharman
  • 30,962
  • 25
  • 85
  • 135
Dev
  • 9
  • 1
  • 2
0

If you want to set corner radius of your whole app then you can paste this line in values/themes/themes.xml. It will set corner radius on your whole app dialogs.

<item name="dialogCornerRadius">10dp</item>