Search code examples
androidkotlinandroid-statusbar

How to make a transparent status and navigation bar solid again?


I've made the status and navigation bar go transparent, like so:

window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)

This works perfectly! But then, when a certain button is tapped, I want it go back to a solid color again with:

    window.statusBarColor = ContextCompat.getColor(this, R.color.white)
    window.navigationBarColor = ContextCompat.getColor(this, R.color.white)
    window.decorView.systemUiVisibility = SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR

But the status bar still shows as transparent, is this working for other people? Or am I just doing something wrong on my part? And help would be really appreciated, thank you!


Solution

  • You can clear the window flags on button click like this.

    window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)