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.

- 67,741
- 15
- 184
- 220

- 5,193
- 5
- 37
- 68
6 Answers
You can make it easily like this:
Dialog(onDismissRequest = {}) {
(LocalView.current.parent as DialogWindowProvider)?.window?.setDimAmount(0f)
// dialog content here...
}

- 394
- 4
- 7
-
1This is the best answer so far. Have been looking for a good solution for a long time. Thanks – odifek Mar 30 '23 at 12:45
-
1You are my savior. thanks. – Wonsik Sung Jul 12 '23 at 07:55
-
This also effects on alertdialog in devices with bigger fonts and display size the dialog takes full width which is side effect of this. – Unique Identifier Aug 09 '23 at 09:20
-
maybe you need to use Modifier.padding() in your dialog layout – Igor Konyukhov Aug 09 '23 at 18:53
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
}
}

- 61
- 1
- 2
This behavior is controlled by android.view.Window
.
It lies deep under Dialog
and the only way I can think of to change it is to copy all the source code.
Then, in this line of the source code, you can insert the following:
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)

- 67,741
- 15
- 184
- 220
You could possibly use a full screen dialog and then insert a card into it with the text that you want. For instance:
AlertDialog(
modifier = Modifier.fillMaxSize(),
backgroundColor = Color.White.copy(alpha = 0.2f),
properties = DialogProperties(usePlatformDefaultWidth = false),
You can add your Card Composable in the text part:
text = {
Card(Modifier.size(200.dp)) {
Text(text = "test")
}
}
Hope this helps!

- 6,222
- 2
- 29
- 50
-
Thanks but I don't want to create a new screen. I want to change the transparency of the current screen irrespective of its contents when a dialog is shown on top of it. – AndroidDev Apr 06 '22 at 19:55
Set decorFitsSystemWindows
to false seems quite workable if you want to set transparent background.
Dialog(
onDismissRequest = { /*TODO*/ },
properties = DialogProperties(decorFitsSystemWindows = false)
) {
}

- 27,554
- 16
- 95
- 105
You might be able to achieve this by changing the window attributes. Here's how you can do it in a Dialog:
Dialog(
onDismissRequest = {
}
) {
val curView = LocalView.current
/* Change the transparency of the dialog window */
LaunchedEffect(curView) {
tailrec fun Context.findWindow(): Window? = when (this) {
is Activity -> window
is ContextWrapper -> baseContext.findWindow()
else -> null
}
fun View.findWindow(): Window? =
(parent as? DialogWindowProvider)?.window ?: context.findWindow()
try {
val window = curView.findWindow() ?: return@LaunchedEffect
val lp = window.attributes
lp.dimAmount = dimAmount // Modify the dim amount value
window.attributes = lp
} catch (e: Throwable) {
e.printStackTrace()
}
}
// content
}

- 96
- 3