'How to Change Statusbar (Text and Background) Colors? [Android]

After many searches I didn't find a complete answer for my behavior:

1- I want the activity layout to be behind the status bar. 2- Transparent status bar background. 3- (optionally) make status bar Translucent. 4- change status bar textColor to black or white.

What have I done so far?

  • In AppTheme.xml

     <item name="android:windowTranslucentStatus">true</item>
    
  • In activity:

        activity.apply {
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
            window.statusBarColor = ContextCompat.getColor(this, android.R.color.transparent)
            WindowCompat.setDecorFitsSystemWindows(window, false)
            ViewCompat.setOnApplyWindowInsetsListener(view) { root, windowInset ->
                val inset = windowInset.getInsets(WindowInsetsCompat.Type.systemBars())
                root.updateLayoutParams<ViewGroup.MarginLayoutParams> {
                    leftMargin = inset.left
                    bottomMargin = inset.bottom
                    rightMargin = inset.right
                }
                WindowInsetsCompat.CONSUMED
            }
        }
    }
    
    

This gives me :

  • Layout is behind the status bar with transparent background & Translucent status bar

this missing thing is to color the text in status bar to white



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source