4

How do i change the status bar icon of my notification between dark and light depending on the status bar.

In some apps, the status bar is dark, in which case the icon should be light, and in others the status bar is light, in which case the icon should be dark.

So how do i get a Status bar icon that displays gray in apps with light theme, and displays white in dark theme apps?

Thank you in advance.

EDIT: What i need to know, is how to change my apps notifications status bar ICON color to light / dark, I DO NOT want to change the status bar color.

Example: YouTube application notification icons in status bar are usually bright, but change to dark icons when the status bar is light.

Skosh
  • 165
  • 1
  • 9

2 Answers2

3

Unfortunately, you can't use dark icons in status bar below 23 API level. You can have a separate themes for 23+ and below API levels and then use this attributes in your theme to have a light status bar and a dark icons:

<item name="android:windowLightStatusBar">true</item>

UPDATE: Actually you can't change a color of an icon itself. The system processes it independently. It always draw white icons on the dark status bar. If you want to have a dark icons on a light status bar - you should tell the system, that you're using a light status bar via that attribute, that I've mentioned above. But it can be achieved only in 23+ API level.

Yurii Kyrylchuk
  • 809
  • 7
  • 16
0

You can use this code snippet:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (darkIcons) {
            window.decorView.systemUiVisibility = window.decorView.windowSystemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
        } else {
            window.decorView.systemUiVisibility = window.decorView.windowSystemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()
        }
    }
Samir Alakbarov
  • 1,120
  • 11
  • 21