DialogFromServiceSample
@Sampled
@Composable
fun DialogFromServiceSample() {
// In a real Service scenario, appWindowToken would be received via IPC
// from the main application process. This sample simulates having the token.
val appWindowToken: IBinder? = null // Provided via IPC
var showDialog by remember { mutableStateOf(false) }
Button(onClick = { showDialog = true }) { Text("Show Dialog From Service") }
if (showDialog) {
Dialog(
onDismissRequest = { showDialog = false },
properties =
DialogProperties(
// Pass the application's window token
windowToken = appWindowToken
),
) {
Box(Modifier.size(250.dp, 150.dp).background(Color.DarkGray)) {
Text("Dialog Content (Service)", color = Color.White)
}
}
}
}
DialogWithBlurSample
@Sampled
@Composable
fun DialogWithBlurSample() {
// Tip: Displaying rich content or an image behind the dialog makes the blur effect clearly
// visible.
Dialog(
onDismissRequest = {},
properties =
DialogProperties(
blurBehindRadius = 15.dp,
backgroundBlurRadius = 30.dp,
scrimAlpha = 0.2f,
),
) {
Box(modifier = Modifier.padding(24.dp)) {
Text(text = "Dialog", color = Color.White, modifier = Modifier.padding(24.dp))
}
}
}