Ask Your Question
2

In Jetpack Compose Dialog, what is the process for drawing behind the system status bar?

asked 2023-04-06 11:00:00 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-02-04 07:00:00 +0000

ladyg gravatar image

To draw behind the system status bar in Jetpack Compose Dialog, you can use the SystemUiController API.

Here is the process:

  1. In the onCreate method of your activity, create an instance of SystemUiController.
val systemUiController = rememberSystemUiController()
  1. Call the setStatusBarColor method of SystemUiController and pass it a transparent color.
systemUiController.setStatusBarColor(Color.Transparent, darkIcons = true)
  1. In your dialog code, use the Modifier.statusBarsPadding() modifier to add padding to your content to avoid overlapping with the system status bar.
AlertDialog(
    onDismissRequest = dismiss,
    title = { Text(text = "Title") },
    text = { Text(text = "Content") },
    confirmButton = {
        Button(
            onClick = { /* Handle confirm button click */ },
            modifier = Modifier.statusBarsPadding()
        ) {
            Text("Confirm")
        }
    },
    dismissButton = {
        Button(
            onClick = dismiss,
            modifier = Modifier.statusBarsPadding()
        ) {
            Text("Cancel")
        }
    },
)

By using Modifier.statusBarsPadding(), Jetpack Compose automatically adds padding to your dialog content, ensuring that it is not obscured by the system status bar.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-04-06 11:00:00 +0000

Seen: 13 times

Last updated: Feb 04 '22