Home > Software engineering >  facing problem in changing status bar color in jetpack compose
facing problem in changing status bar color in jetpack compose

Time:11-16

I have two activities in my app, one is the home.kt and another is the about.kt, for both screens I have different background color, in the home.kt file I set the status bar color to background color.

rememberSystemUiController().setStatusBarColor(
    MaterialTheme.colors.background, darkIcons = MaterialTheme.colors.isLight
)

When I move to about.kt I again tried to match its color to background but the status bar keeps its original color which was set in home.kt

rememberSystemUiController().setStatusBarColor(
    MaterialTheme.colors.surface, darkIcons = MaterialTheme.colors.isLight
)
//This piece is having no effect

CodePudding user response:

In each activity, instead of using:

rememberSystemUiController().setStatusBarColor,

use this (replace 0xff0000 with your background color):

activity.window?.setStatusBarColor(0xff0000)

Place that inside your composable so that it gets called each time your composable recomposes.

CodePudding user response:

For that, too google has created a library called accompanist. You can find it here: https://github.com/google/accompanist

like in this module have multiple module for jetpack compose, system controller so you can change by using it

for more understanding see the document :-- https://google.github.io/accompanist/systemuicontroller/

  • Related