Android statusbar icons color
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>
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
Related videos on Youtube
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, 2021Comments
-
GuilhE over 2 years
I was wondering if it's possible to change the statusbar icons colour (not the statusbar colour,
colorPrimaryDark
) 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
-
GuilhE about 9 yearsI 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 almost 9 yearsThere'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 over 7 yearsNice solution! It was really suitable for my application because I didn't have to change the SDK version.
-
Anton Savenok over 7 yearsit is more correct: decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
-
Numanqmr about 6 yearsThis is the best solution, also works on MI phones. You're a savior!
-
meditat almost 6 yearsYou mean 23. :(
-
Ritesh almost 6 yearsNo 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 almost 6 yearsIf you look at Google's news app they do not have white status bar icons: play.google.com/store/apps/…
-
AdamHurwitz almost 6 years
<item name="android:windowLightStatusBar">true</item>
worked for me. -
Dominique over 5 yearsAre 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 over 5 yearsbut its menu items icons color is still white how to change its menu item icons color to black?
-
Daniel F about 5 yearsI wonder why the Gmail App (as released in 2019-04) colors the status bar white and the icons/text dark-grey.
-
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 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 almost 5 yearsHow 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 over 4 yearsThis is for foreground notifications only and only applies to the notification item - not the notification icon.
-
Subaru Tashiro over 4 yearsEven 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 over 4 yearswhat is ShouldChangeStatusBarTintDark please??
-
Andrew Chelix over 3 yearsIs there a constant value for zero e.g View.SYSTEM_UI_FLAG_DARK_STATUS_BAR
-
Amin almost 3 yearshow can i change the top codes for lower APIs
-
Androidz almost 3 yearsIf it doesn't work remove "android:windowLightStatusBar" from theme's style
-
Leonardo Sibela over 2 yearsThis code is not compiling. It says "Unresolved reference: getWindowInsetsController"
-
Mark Andrew about 2 years@LeonardoSibela can you provide the compelete line of code
-
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 about 2 yearsThanks 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 .