0

I'm creating an app in Android Studio. I created an AlertDialog with the background of the layout set to this custom xml:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <solid android:color="@color/connectioncardColor" />
        <corners android:bottomRightRadius="8dp"
            android:bottomLeftRadius="8dp"
            android:topRightRadius="8dp"
            android:topLeftRadius="8dp"/>
        <stroke
            android:color="@color/colorPrimaryDark"
            android:width="1dp"/>
    
    </shape>

The corners of the background are nice and rounded but behind the background is another layer of white. So there is bit of white in the corner, how to remove that?

White in corner

Halil Ozel
  • 2,482
  • 3
  • 17
  • 32
aWiseMan
  • 61
  • 6

2 Answers2

0

Create your custom style for dialog

 <style name="MyDialog" parent="android:Theme.Dialog">        
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
 </style>

then add this style in builder

AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.MyDialog)
Pradeepvina
  • 90
  • 1
  • 7
  • the white in the corner is gone, but now its has a grey outline and is very narrow. (the width of the dialog is now only about 1/5 of the screen width). – aWiseMan May 25 '22 at 13:27
0

Since I cant just post a link I will copy the answer too, but I found my answer here: How to make custom dialog with rounded corners in android

Create an XML file in drawable, say dialog_bg.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid
        android:color="@color/white"/>
    <corners
        android:radius="30dp" />
    <padding
        android:left="10dp"
        android:top="10dp"
        android:right="10dp"
        android:bottom="10dp" />
</shape>

set it as the background in your layout XML:

android:background="@drawable/dialog_bg"

Set the background of the dialog's root view to transparent, because Android puts your dialog layout within a root view that hides the corners in your custom layout.

Java:

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

Kotlin:

dialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
aWiseMan
  • 61
  • 6