5

I want to change status bar icons color from white to black. I try below code but I can't make it. Could you help me please?

Activity Code:

public static void setLightStatusBar(View view,Activity activity){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int flags = view.getSystemUiVisibility(); flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; view.setSystemUiVisibility(flags); activity.getWindow().setStatusBarColor(Color.WHITE); } } 

style.xml code:

<item name="android:windowLightStatusBar">true</item> 
3
  • You want to change icon color . Are Time and other icon in the top ? Commented Sep 9, 2017 at 15:04
  • @KeLiuyue Yes. I want to change status bar text and icon color. Commented Sep 9, 2017 at 15:07
  • Have a look at this answer(Make the status bar white with black icons). Commented Nov 9, 2022 at 13:40

4 Answers 4

7

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> 
Sign up to request clarification or add additional context in comments.

5 Comments

Unfortunately It doesn't work. My phone is OnePlus One. Android version is 6.0.1
You can try again . @MuhammedCobanoglu
Could you try second way in your code ? I use HUA WEI and is ok . Also you can try @MuhammedCobanoglu
I tried with Samsung A3 2017. It worked. Thanks for everything.
@MuhammedCobanoglu ,Good luck to you!
2

This did it for Android version >= 21:

activity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); activity.getWindow().setStatusBarColor(0x000000); 

1 Comment

this really worked!! I don't know WHY? my issue was that i needed write status bar and setting only SYSTEM_UI_FLAG_LIGHT_STATUS_BAR made the screen layout disappear on API 23 (only!)
0

Make status bar icon color black

getWindow().getDecorView().getWindowInsetsController().setSystemBarsAppearance(APPEARANCE_LIGHT_STATUS_BARS, APPEARANCE_LIGHT_STATUS_BARS); 

Maker status bar icon color white

getWindow().getDecorView().getWindowInsetsController().setSystemBarsAppearance(0, APPEARANCE_LIGHT_STATUS_BARS); 

Comments

0

Try this. make status bar icon color black with Java

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { View decor = getWindow().getDecorView(); boolean shouldChangeStatusBarTintToDark = true; getWindow().setStatusBarColor(Color.WHITE); 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); } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.