Search code examples
androidkotlinstatusbarandroid-theme

Why doesn't isAppearanceLightStatusBars affect on Status bar content color programmatically?


I've tried to change the color of status bar content using isAppearanceLightStatusBars:

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash_screen)
        WindowCompat.setDecorFitsSystemWindows(window, false)

        val controller = ViewCompat.getWindowInsetsController(window.decorView)
        controller?.isAppearanceLightStatusBars = true
}

it doesn't change anything, but when i change it in theme xml file, it works normal:

<style name="Theme.NutShop" parent="Theme.MaterialComponents.NoActionBar">
        <item name="android:windowLightStatusBar" tools:targetApi="23">true</item>
</style>

I need to know the reason of this problem, and solution, thanks.


Solution

  • I've found the problem, ViewCompat.getWindowInsetsController(window.decorView) is returning null, so i changed it with WindowCompat.getWindowInsetsController(window, window.decorView) then it worked now, but still don't know why the first one is returning null.