I have a custom Dialog, which I inflate and use. Now I wanted to have rounded corners which proves to be rather difficult. And it seems that one of those hacks made it so my Dialog doesn't change size no matter if the width is WrapContent, 10dp, 20dp, 200dp or 300dp. It changes in the layout editor but when I actually launch the app it stays the same.
Editor
InApp
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="@drawable/dialog_background"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="Do you want to reset progress?"
android:textColor="@color/black"
android:textSize="18sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/cancel_button"
style="@style/basicButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:backgroundTint="@color/delete_red"
android:padding="10dp"
android:text="Cancel"
android:textColor="@color/white"
android:textSize="20sp" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/confirm_button"
style="@style/basicButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Yes"
android:textSize="20sp" />
<nearLayout>
</LinearLayout>nearLayout>
</LinearLayout>
And this is where I build it (note the links in the comments, I think that's what causes the problems, setting the background of the window).
val builder = AlertDialog.Builder(requireContext())
val dialogBinding = ResetProgressDialogBinding.inflate(layoutInflater)
builder.setView(dialogBinding.root)
val dialog = builder.create()
dialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)); // https://stackoverflow.com/questions/28937106/how-to-make-custom-dialog-with-rounded-corners-in-android
dialogBinding.root.clipToOutline = true // https://issuetracker.google.com/issues/37036728
And my shape
<?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="10dp" />
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
</shape>