Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change statusbar and navigation bar color in JetpackCompose App?

I want to change status bar and navigation bar color in my app by default it is not set. This is my composeable AppTheme function which I need to apply the change in.

val view = LocalView.current
    if (!view.isInEditMode) {
        SideEffect {
            val window = (view.context as Activity).window
            window.statusBarColor = colorScheme.primary.toArgb()
            WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
        }
    }
private val DarkColorScheme = darkColorScheme(
    primaryContainer = Color.Black,
    onPrimaryContainer = Color.White
)
private val LightColorScheme = lightColorScheme(
    primary = RoyalBlue,
    primaryContainer = RoyalBlue,
    onPrimaryContainer = Color.White
)
like image 613
Aashir Hussnain Avatar asked Jan 24 '26 14:01

Aashir Hussnain


2 Answers

EDIT

The use val systemUiController = rememberSystemUiController() is deprecated : https://google.github.io/accompanist/systemuicontroller/

Use custom method or try with "androidx.activity:activity" library v1.8.0-rc01 in your activity. Do something like this :

enableEdgeToEdge(
    statusBarStyle = SystemBarStyle.auto(
        MaterialTheme.colors.primary.toArgb(),
        MaterialTheme.colors.primary.toArgb()
    ),
    navigationBarStyle = SystemBarStyle.auto(
        MaterialTheme.colors.primary.toArgb(),
         MaterialTheme.colors.primary.toArgb()
     )
)
like image 148
Lixy Avatar answered Jan 27 '26 04:01

Lixy


Add this line in your AppTheme Composable Function:

window.statusBarColor = if (darkTheme)  Color.Black.toArgb() else RoyalBlue.toArgb()

here change the color according to your dark and light colors.

Also to change the navigation bar color add these lines of code in AppTheme composable:

val systemUiController = rememberSystemUiController()
if (darkTheme) {
    systemUiController.setSystemBarsColor(
        color = Color.Black
    )
} else {
    systemUiController.setSystemBarsColor(
        color = RoyalBlue
    )
}

Change the colors accordingly of your choice.

like image 43
Fatiq Hussnain Avatar answered Jan 27 '26 03:01

Fatiq Hussnain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!