170

I was wondering if it's possible to change the statusbar icons colour (not the statusbar colour, colorPrimaryDark) enter image description here Let's say I want this statusbar with:
<item name="colorPrimaryDark">@android:color/white</item>

and the icons in black, is it possible?

Thanks.

EDIT:

New in the M developer preview: windowLightStatusBar. Flipping this on in your theme tells the system to use a dark foreground, useful for lighter colored status bars. Note the M preview seems to have a bug where notification icons remain white, while system status icons correctly change to semitransparent black.

from: Roman Nurik Google+ post enter image description here

GuilhE
  • 11,591
  • 16
  • 75
  • 116

11 Answers11

262

Yes it's possible to change it to gray (no custom colors) but this only works from API 23 and above you only need to add this in your values-v23/styles.xml

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

enter image description here

eOnOe
  • 2,883
  • 2
  • 12
  • 7
130

@eOnOe has answered how we can change status bar tint through xml. But we can also change it dynamically in code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    View decor = getWindow().getDecorView();
    if (shouldChangeStatusBarTintToDark) {
        decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    } else {
        // We want to change tint color to white again.
        // You can also record the flags in advance so that you can turn UI back completely if
        // you have set other flags before, such as translucent or full screen.
        decor.setSystemUiVisibility(0);
    }
}
ywwynm
  • 11,573
  • 7
  • 37
  • 53
53

if you have API level smaller than 23 than you must use it this way. it worked for me declare this under v21/style.

<item name="colorPrimaryDark" tools:targetApi="23">@color/colorPrimary</item>
        <item name="android:windowLightStatusBar" tools:targetApi="23">true</item>
Ritesh
  • 876
  • 9
  • 14
  • 2
    You mean 23. :( – meditat Jul 03 '18 at 08:53
  • No I meant v21/Style if you don't know about that than please visit this link. https://stackoverflow.com/questions/28465064/creating-styles-v21-xml – Ritesh Jul 04 '18 at 05:01
  • 5
    Even if placed in a styles.xml with v21 qualifier this only works on devices running api 23 and above. In fact AS Lint highlights these items with a warning saying it will be ignored on android versions that doesn't support it. The `tools:targetApi="23"` part tells Lint to suppress this warning. – Subaru Tashiro Oct 10 '19 at 13:26
29

Not since Lollipop. Starting with Android 5.0, the guidelines say:

Notification icons must be entirely white.

Even if they're not, the system will only consider the alpha channel of your icon, rendering them white

Workaround

The only way to have a coloured icon on Lollipop is to lower your targetSdkVersion to values <21, but I think you would do better to follow the guidelines and use white icons only.

If you still however decide you want colored icons, you could use the DrawableCompat.setTint method from the new v4 support library.

Kuba Spatny
  • 26,618
  • 9
  • 40
  • 63
  • 3
    I did some google search and I couldn't find a proper way to this but If Android guidelines say that icons must be white, white it is :) Thanks! – GuilhE May 06 '15 at 12:48
  • 14
    There's got to be a better workaround for this. Several commercial apps out there are using colors. This is a horribly idiotic design move by Google. What were they thinking again, if at all? – not2qubit Jun 22 '15 at 06:30
  • 1
    If you look at Google's news app they do not have white status bar icons: https://play.google.com/store/apps/details?id=com.google.android.apps.magazines&hl=en_US – AdamHurwitz Sep 13 '18 at 00:13
  • 6
    `true` worked for me. – AdamHurwitz Sep 13 '18 at 00:21
  • I wonder why the Gmail App (as released in 2019-04) colors the status bar white and the icons/text dark-grey. – Daniel F Apr 15 '19 at 15:01
  • @DanielF A lot of apps that are mostly white/light use the `windowLightStatusBar` style, for example Gmail, Google Photos, Pinterest, Instagram and more – Kuba Spatny Apr 16 '19 at 14:18
  • "Notification icons must be entirely white." that's funny tho, Google News is using gray color. Why would they set standards if they don't follow them?! – Farid Jul 26 '19 at 13:27
  • How would one use the DrawableCompat.setTint method on the status bar icons? I am not sure how to access the actual drawables o.O – Hayuki Aug 16 '19 at 12:43
11

SystemUiVisibility flags are deprecated. Use WindowInsetsController instead

the code below sets the color of icons to black (for the light statusbar)

//icon color -> black  
activity.getWindow().getDecorView().getWindowInsetsController().setSystemBarsAppearance(APPEARANCE_LIGHT_STATUS_BARS, APPEARANCE_LIGHT_STATUS_BARS);

and the code below clears it(i.e. turns icon color to white for dark statusbar):

//icon color -> white
activity.getWindow().getDecorView().getWindowInsetsController().setSystemBarsAppearance(0, APPEARANCE_LIGHT_STATUS_BARS);

link to docs : https://developer.android.com/reference/android/view/WindowInsetsController#setSystemBarsAppearance(int,%20int)

Mark Andrew
  • 121
  • 1
  • 4
5

Setting windowLightStatusBar to true not works with Mi phones, some Meizu phones, Blackview phones, WileyFox etc. I've found such hack for Mi and Meizu devices. This is not a comprehensive solution of this perfomance problem, but maybe it would be useful to somebody.

And I think, it would be better to tell your customer that coloring status bar (for example) white - is not a good idea. instead of using different hacks it would be better to define appropriate colorPrimaryDark according to the guidelines

Jackky777
  • 644
  • 12
  • 19
5

You can do it programmatically with retaining all other system UI visibility flags.

public static void changeStatusBarContrastStyle(Window window, Boolean lightIcons) {
     View decorView = window.getDecorView();
     if (lightIcons) {
         // Draw light icons on a dark background color
         decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
     } else {
         // Draw dark icons on a light background color
         decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
     }
 }
Mahmoud
  • 2,683
  • 1
  • 30
  • 32
  • 1
    Thanks mahmoud, Been looking for this from long time. other solutions needed changes to the theme and style which caused problems in the current screens design . this solution has no side effects . – A.Alqadomi May 17 '22 at 10:43
1

in kotlin you can use following lines

    val window = this.window
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
    window.statusBarColor = ContextCompat.getColor(this, R.color.white)
    WindowCompat.getInsetsController(window, window.decorView).apply {
        isAppearanceLightStatusBars = true
    }
Swapnil
  • 121
  • 7
0

This is for all those who want to change their application's Notification small icon color can use this setColor method of NotificationCompat.Builder

Example:

val builder = NotificationCompat.Builder(this, "whatever_channel_id")
        **.setSmallIcon(R.drawable.ic_notification) //set icon for notification**
        .setColor(ContextCompat.getColor(this, R.color.pink))
        .setContentTitle("Notification Title")
        .setContentText("Notification Message!")
Kishan Solanki
  • 13,761
  • 4
  • 85
  • 82
0

I used two line of code for different status bar color

1st: If status bar color is white then use this line of code to visible the status bar icon:

  pingAct.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
  
      

2nd: If you use dark color then use this line of code to make visible the status bar icon:

 pingAct.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);

               
Pir Fahim Shah
  • 10,505
  • 1
  • 82
  • 81
-3

Yes you can change it. but in api 22 and above, using NotificationCompat.Builder and setColorized(true) :

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, context.getPackageName())
                .setContentTitle(title)
                .setContentText(message)
                .setSmallIcon(icon, level)
                .setLargeIcon(largeIcon)
                .setContentIntent(intent)
                .setColorized(true)
                .setDefaults(0)
                .setCategory(Notification.CATEGORY_SERVICE)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setPriority(NotificationCompat.PRIORITY_HIGH);
hadi seylani
  • 117
  • 1
  • 7
  • Are you sure? The documentation says "When set, the color set with setColor(int) will be used as the background color of this notification." and "For most styles, the coloring will only be applied if the notification is for a foreground service notification." It does not seem to be possible to change the foreground color of the icon. – Dominique Dec 28 '18 at 08:27
  • This is for foreground notifications only and only applies to the notification item - not the notification icon. – Subaru Tashiro Oct 10 '19 at 13:20