Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Compose Dialog - Is there a way to change the background transparency?

When we show a Dialog/AlertDialog in Jetpack Compose the background seems to be a bit dark, is there a way to adjust the background alpha or make it transparent? For eg: The White background in this image is turned into Dark grey when the dialog is shown.

like image 429
AndroidDev Avatar asked Sep 02 '25 16:09

AndroidDev


2 Answers

You can make it easily like this:

Dialog(onDismissRequest = {}) {
    (LocalView.current.parent as DialogWindowProvider)?.window?.setDimAmount(0f)
    // dialog content here...
   }
like image 79
Igor Konyukhov Avatar answered Sep 05 '25 07:09

Igor Konyukhov


I was try with Dialog and no way to clear flag WindowManager.LayoutParams.FLAG_DIM_BEHIND.

You can try to use Popup to replace Dialog, everything work good for me.

Popup(
        onDismissRequest = {},
        properties = PopupProperties(
            focusable = true,
            dismissOnBackPress = false,
            dismissOnClickOutside = false,
            excludeFromSystemGesture = true,
        )
    ) {
        Box(
            contentAlignment = Alignment.Center,
            modifier = Modifier
                .fillMaxSize()
                .background(Color.Transparent)
        ) {
            // Your content code is here
        }
    }
like image 31
Cuong Le Q. Avatar answered Sep 05 '25 06:09

Cuong Le Q.