AlertDialog in Android Api 29 used to dim the screen except for the dialog when it was shown, but in Api 34 instead it creates a shadow around the dialog.
The AlertDialog in android used to dim the screen like this enter image description here
but now it just adds shadow around the box like this enter image description here
I have tried the methods dialog.window?.setDimAmount() I have tried github libraries
But they all dont work
Kotlin Code
private fun showPopup(){
val dialogBuilder: AlertDialog.Builder = AlertDialog.Builder(this)
val dialog = dialogBuilder.create()
val inflater = this.layoutInflater
val dialogView: View = inflater.inflate(R.layout.popup_sharing_number, null)
dialog.setView(dialogView)
dialog.show()
}
Layout Code
<!-- popup_layout.xml -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/background_alert_box"
android:padding="10dp">
<ImageView
android:layout_marginTop="5dp"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/icon_alert"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Why do I need to share my number?"
android:textSize="26sp"
android:textAlignment="center"
android:textStyle="bold"
android:textColor="@color/primaryColor"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="16dp"
android:textAlignment="center"
android:text="For security reasons, we only use phone number as an authentication method. This counts for Students, Parents and Tutors. We will never charge via phone number"
android:textColor="#7E8082"
android:textSize="20sp" />
<Button
android:id="@+id/btnClose"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:text="Close"
android:background="@drawable/button_primary"
android:textSize="16sp"
android:layout_gravity="center_horizontal"
android:padding="12dp"/>
</LinearLayout>
I want it to Dim in all versions
This was an emulator rendering bug, now fixed as of January 2024. Now dialogs render the dimmed background correctly. https://issuetracker.google.com/issues/289117017
Bug present in API 34 v8a emulator revision 11, emulator 33.1.23
Bug fixed in API 34 v8a emulator revision 12, emulator 33.1.24