Home > Net >  White Status Bar in dark mode
White Status Bar in dark mode

Time:01-25

Is it possible to make white status bar programmatically in dark mode? (Application is based on single Activity, and I have to make this only for one fragment)

also app should based on Theme.MaterialComponents.Light.NoActionBar to have no bad effect on other styles.

I've tried to set white color and ui visibility to light mode, but it seems force dark is applied to status bar background automatically.

the code looks like this:

var flags = it.decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
window.decorView.systemUiVisibility = flags

                     //it is #F0F0F0 in white and night sources 
var statusBarColor = context.getColorCompat(R.color.white) 
window?.statusBarColor = statusBarColor

but only systemUiVisibility flag applies:

enter image description here

CodePudding user response:

Add this to Util file

private val insetsController: WindowInsetsControllerCompat? by lazy {
  activity?.window?.decorView?.let(ViewCompat::getWindowInsetsController)
}

private fun setLightStatusBar(light: Boolean) {
    insetsController?.isAppearanceLightStatusBars = light
}

Hope it will solve your issue.

CodePudding user response:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(Color.BLUE);
}

and an other way is to create 2 themes class and define specific color for status bar.

  • Related