Android: Change status bar text color with WHITE/BLACK

Android: Change status bar text color with WHITE/BLACK

Image for post

For API >= 23

From API v23 and above specific stuff, you can add the following to your AppTheme styles.xml:

Solution 1

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);// View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR: make the text of staus bar to black

Solution 2

<item name=”android:statusBarColor”>@color/colorPrimaryDark</item><item name=”android:windowLightStatusBar”>true</item>

when android:windowLightStatusBar is set to true, status bar text color will be able to be seen when the status bar color is white, and when android:windowLightStatusBar is set to false, status bar text color will be designed to be seen when the status bar color is dark.

Example

<!– Base application theme. –><style name=”AppTheme” parent=”Theme.AppCompat.Light.DarkActionBar”> <!– Customize your theme here. –> <item name=”colorPrimary”>@color/colorPrimary</item> <item name=”colorPrimaryDark”>@color/colorPrimaryDark</item> <item name=”colorAccent”>@color/colorAccent</item> <item name=”android:statusBarColor”>@color/colorPrimaryDark</item> <item name=”android:windowLightStatusBar”>true</item> </style>

For API < 23

It?s not possible to change the color of the status bar in android. The only thing you can set in your app is the status bar?s background color.

Here is how you can change the color of the status bar using the new window.setStatusBarColor method introduced in API level 21.

Changing the color of status bar also requires setting two additional flags on the Window; you need to add the FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag and clear the FLAG_TRANSLUCENT_STATUS flag.

Window window = activity.getWindow();// clear FLAG_TRANSLUCENT_STATUS flag:window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);// add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the windowwindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);// finally change the colorwindow.setStatusBarColor(ContextCompat.getColor(activity,R.color.my_statusbar_color));

See mores at:

IMStudio – Medium

Read writing from IMStudio on Medium. Developer. Every day, IMStudio and thousands of other voices read, write, and?

medium.com

https://developer.android.com/reference/android/view/Window.html#setStatusBarColor(int)

33

No Responses

Write a response