Android Statusbar Icons Color

Android statusbar icons color

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.

How to change status bar icons color in Android?

You can't actually change the status bar icon color in android like that. You can still change the status bar color to whatever you want, but for status bar icons, there are only 2 options - Light (white) or Dark (gray).

If you want to use white icons, then simply put <item name="android:windowLightStatusBar">false</item> attribute in your base application theme. For dark icons <item name="android:windowLightStatusBar">true</item>

You can also do it programmatically like mentioned here - https://stackoverflow.com/a/39596725/10357086

How to customize status bar icons and text color? E.g. status bar background: white, status bar icon color, and text: red

Yes,android only supports black or white icons & text.

We can change the statusBarColor of status bar by property android:statusBarColor in file styles.xml:

 <item name="android:statusBarColor">@color/colorgreen</item>

And when we change the value of property android:windowLightStatusBar to true,the color of icons & text will be grayed out.

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

When using the following code:

<style name="AppTheme.NoActionBar">
<!-- other code -->
<item name="android:statusBarColor">@color/colorgreen</item>
<item name="android:windowLightStatusBar">true</item>
</style>

The result is:

Sample Image

How to change status bar icon color in Android?

Try this .

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
activity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
// edited here
activity.getWindow().setStatusBarColor(Color.WHITE);
}

Then set at the root layout

android:fitsSystemWindows="true"

Another way

Try this in your code .

public static int StatusBarLightMode(Activity activity) {
int result = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (MIUISetStatusBarLightMode(activity, true)) {
result = 1;
} else if (FlymeSetStatusBarLightMode(activity.getWindow(), true)) {
result = 2;
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
result = 3;
}
}
return result;
}


public static boolean FlymeSetStatusBarLightMode(Window window, boolean dark) {
boolean result = false;
if (window != null) {
try {
WindowManager.LayoutParams lp = window.getAttributes();
Field darkFlag = WindowManager.LayoutParams.class
.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
Field meizuFlags = WindowManager.LayoutParams.class
.getDeclaredField("meizuFlags");
darkFlag.setAccessible(true);
meizuFlags.setAccessible(true);
int bit = darkFlag.getInt(null);
int value = meizuFlags.getInt(lp);
if (dark) {
value |= bit;
} else {
value &= ~bit;
}
meizuFlags.setInt(lp, value);
window.setAttributes(lp);
result = true;
} catch (Exception e) {

}
}
return result;
}

public static boolean MIUISetStatusBarLightMode(Activity activity, boolean dark) {
boolean result = false;
Window window = activity.getWindow();
if (window != null) {
Class clazz = window.getClass();
try {
int darkModeFlag = 0;
Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
darkModeFlag = field.getInt(layoutParams);
Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
if (dark) {
extraFlagField.invoke(window, darkModeFlag, darkModeFlag);
} else {
extraFlagField.invoke(window, 0, darkModeFlag);
}
result = true;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (dark) {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}

Then use StatusBarLightMode(this); in your code .

And it can make your status text and icon to be black .

Edit

Starting with Android 6.0, Google official provides support for configuring android:windowLightStatusBar in the style property
Yes, when set to true, when the background color of the statusbar is light, the text color of the statusbar becomes grayed out for false.

<style name="statusBarStyle" parent="@android:style/Theme.DeviceDefault.Light">
<item name="android:statusBarColor">@color/status_bar_color</item>
<item name="android:windowLightStatusBar">false</item>
</style>

How can I make the status bar white with black icons?

With Android M (api level 23) you can achieve this from theme with android:windowLightStatusBar attribute.

Edit :

Just as Pdroid mentioned, this can also be achieved programatically:

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


Related Topics



Leave a reply



Submit