1

In this below image,

the status bar background is:black

and, status bar text color is:white

status bar with background color as black and text color as white

so, how do we change the status bar text color? ..as you can see, the contents of the status bar is displayed in white now, so how do we change it to different color?

Panup Pong
  • 1,871
  • 2
  • 22
  • 44
sharan
  • 226
  • 1
  • 4
  • 12

2 Answers2

3

You can not set the status bar text color by specifying any color explicitly.

But you can try to use "android:windowLightStatusBar" which is Added in API 23,

You can find more details here: https://developer.android.com/reference/android/R.attr.html#windowLightStatusBar

radu_paun
  • 1,940
  • 21
  • 25
-3

You can set the status bar color programatically using the following code.

Note: The code is in C#, you can convert it into equivalent java code. Also, the status bar text color can either be white(in a dark theme) or black(in a light theme), there are no other options to set the specific color.

private void SetStatusBarColor(Color statusBarColor, StatusBarState state)
{
    if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
    {
        var window = ((Activity)_context).Window;
        window.ClearFlags(WindowManagerFlags.TranslucentStatus);
        window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
        window.SetStatusBarColor(statusBarColor.ToAndroid());
        int newUiVisibility = (int)window.DecorView.SystemUiVisibility;

        if (state == StatusBarState.Light)
        {
            //Dark Text to show up on your light status bar
            newUiVisibility |= (int)SystemUiFlags.LightStatusBar;
        }
        else if (state == StatusBarState.Dark)
        {
            //Light Text to show up on your dark status bar
            newUiVisibility &= ~(int)SystemUiFlags.LightStatusBar;
        }
        window.DecorView.SystemUiVisibility = (StatusBarVisibility)newUiVisibility;
    }
}

public enum StatusBarState
{
    Light,
    Dark
}
Md Naushad
  • 147
  • 1
  • 11