Android Lollipop Set Status Bar Text Color

androidandroid-5.0-lollipop

I'm trying to set the status bar text color in Android v21, but I'm not seeing an API method for it. Here's what I have so far for the background

MyActivity.java > onCreate:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

        window.setStatusBarColor(getResources().getColor(R.color.white));

    }

Obviously white text on white background won't work. I'm looking for something like

window.setStatusBarTextColor(getResources().getColor(R.color.orange));

Best Solution

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

But you can try below alternative which is Added in API 23,

You can use "android:windowLightStatusBar" attribute in two ways

  • "android:windowLightStatusBar" = true, status bar text color will be compatible (grey) when status bar color is light
  • "android:windowLightStatusBar" = false, status bar text color will be compatible (white) when status bar color is dark
<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>

You can check above api in below link - https://developer.android.com/reference/android/R.attr.html#windowLightStatusBar