Android statusbar icons color

AndroidAndroid 5.0-LollipopAndroid StylesAndroid Statusbar

Android Problem Overview


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

Android Solutions


Solution 1 - Android

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 2 - Android

@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 3 - Android

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 4 - Android

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 5 - Android

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

Solution 6 - Android

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)

Solution 7 - Android

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

Solution 8 - Android

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!")

Solution 9 - Android

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGuilhEView Question on Stackoverflow
Solution 1 - AndroideOnOeView Answer on Stackoverflow
Solution 2 - AndroidywwynmView Answer on Stackoverflow
Solution 3 - AndroidRiteshView Answer on Stackoverflow
Solution 4 - AndroidKuba SpatnyView Answer on Stackoverflow
Solution 5 - AndroidJackky777View Answer on Stackoverflow
Solution 6 - AndroidMark AndrewView Answer on Stackoverflow
Solution 7 - AndroidMahmoudView Answer on Stackoverflow
Solution 8 - AndroidKishan SolankiView Answer on Stackoverflow
Solution 9 - Androidhadi seylaniView Answer on Stackoverflow