Android statusbar icons color

140,831

Solution 1

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.

Solution 2

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

Solution 3

@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);
    }
}

Solution 4

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>

Solution 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

Share:
140,831

Related videos on Youtube

GuilhE
Author by

GuilhE

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” - Brian W. Kernighan

Updated on October 08, 2021

Comments

  • GuilhE
    GuilhE over 2 years

    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
    GuilhE about 9 years
    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!
  • not2qubit
    not2qubit almost 9 years
    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?
  • Vitor Braga
    Vitor Braga over 7 years
    Nice solution! It was really suitable for my application because I didn't have to change the SDK version.
  • Anton Savenok
    Anton Savenok over 7 years
    it is more correct: decorView.setSystemUiVisibility(decorView.getSystemUiVisibil‌​ity() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
  • Numanqmr
    Numanqmr about 6 years
    This is the best solution, also works on MI phones. You're a savior!
  • meditat
    meditat almost 6 years
    You mean 23. :(
  • Ritesh
    Ritesh almost 6 years
    No I meant v21/Style if you don't know about that than please visit this link. stackoverflow.com/questions/28465064/creating-styles-v21-xml
  • AdamHurwitz
    AdamHurwitz almost 6 years
    If you look at Google's news app they do not have white status bar icons: play.google.com/store/apps/…
  • AdamHurwitz
    AdamHurwitz almost 6 years
    <item name="android:windowLightStatusBar">true</item> worked for me.
  • Dominique
    Dominique over 5 years
    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.
  • Mateen Chaudhry
    Mateen Chaudhry over 5 years
    but its menu items icons color is still white how to change its menu item icons color to black?
  • Daniel F
    Daniel F about 5 years
    I wonder why the Gmail App (as released in 2019-04) colors the status bar white and the icons/text dark-grey.
  • Kuba Spatny
    Kuba Spatny about 5 years
    @DanielF A lot of apps that are mostly white/light use the windowLightStatusBar style, for example Gmail, Google Photos, Pinterest, Instagram and more
  • Farid
    Farid almost 5 years
    "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?!
  • Hayuki
    Hayuki almost 5 years
    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
  • Subaru Tashiro
    Subaru Tashiro over 4 years
    This is for foreground notifications only and only applies to the notification item - not the notification icon.
  • Subaru Tashiro
    Subaru Tashiro over 4 years
    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.
  • Ibramazin
    Ibramazin over 4 years
    what is ShouldChangeStatusBarTintDark please??
  • Andrew Chelix
    Andrew Chelix over 3 years
    Is there a constant value for zero e.g View.SYSTEM_UI_FLAG_DARK_STATUS_BAR
  • Amin
    Amin almost 3 years
    how can i change the top codes for lower APIs
  • Androidz
    Androidz almost 3 years
    If it doesn't work remove "android:windowLightStatusBar" from theme's style
  • Leonardo Sibela
    Leonardo Sibela over 2 years
    This code is not compiling. It says "Unresolved reference: getWindowInsetsController"
  • Mark Andrew
    Mark Andrew about 2 years
    @LeonardoSibela can you provide the compelete line of code
  • Leonardo Sibela
    Leonardo Sibela about 2 years
    @MarkAndrew thanks for replying, but sadly, I cannot. I solved this problem a while back and I don't remember what was going on. But I do appreciate that you replied. Have a good life bro :)
  • A.Alqadomi
    A.Alqadomi about 2 years
    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 .