How can i set status bar color In my compose app. ...
# compose
g
How can i set status bar color In my compose app. since, android status bar setColor is removed in targetsdk 35. i cant directly set the status bar color. but, google files app has done that.
Copy code
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DetailedDrawerExample(
    content: @Composable (PaddingValues) -> Unit
) {
    val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
    val scope = rememberCoroutineScope()

    ModalNavigationDrawer(
        drawerContent = {
            ModalDrawerSheet() {
                Column(
                    modifier = Modifier.padding(horizontal = 16.dp)
                        .verticalScroll(rememberScrollState())
                ) {
                    Spacer(Modifier.height(12.dp))
                    Text("Drawer Title", modifier = Modifier.padding(16.dp), style = MaterialTheme.typography.titleLarge)
                    HorizontalDivider()

                    Text("Section 1", modifier = Modifier.padding(16.dp), style = MaterialTheme.typography.titleMedium)
                    NavigationDrawerItem(
                        label = { Text("Item 1") },
                        selected = false,
                        onClick = { /* Handle click */ }
                    )
                }
            }
        },
        drawerState = drawerState
    ) {
        Scaffold(
            topBar = {
                TopAppBar(
                    title = { Text("Navigation Drawer Example") },
                    navigationIcon = {
                        IconButton(onClick = {
                            scope.launch {
                                if (drawerState.isClosed) {
                                    drawerState.open()
                                } else {
                                    drawerState.close()
                                }
                            }
                        }) {
                            Icon(<http://Icons.Default.Menu|Icons.Default.Menu>, contentDescription = "Menu")
                        }
                    }
                )
            }
        ) { innerPadding ->
            content(innerPadding)
        }
    }
}
a
you need a reference to
Window
. you can get it via the host activity. I >think< there is a composition local to get the current activity these days. so either use that or forward the window down the tree. I do that on unstyled to forward the dialog's window. you can follow the same pattern PS: this is a better fit for #C04TPPEQKEJ
👍 1
c
setColor
for the status bar was removed because of edge-to-edge that you probably enabled. So you need to handle the window insets yourself and draw a box underneath the stationary with the color you want.
👍 1
g
thanks a lot @Alex Styl @Chrimaeon
both are working for my case.
👍🏻 1