Reputation: 131
I want the icons and text on the StatusBar to be black. I have tried in various ways, but obviously it is a problem because API 30 does not respond to the already existing solutions I found on the net. Can anyone give specific instructions on how to change the color of icons and text. Please note that I am using Theme.AppCompat.DayNight.DarkActionBar
I ask for your help.
This is what it should look like:
My style.xml
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="colorPrimary">@android:color/transparent</item>
<item name="colorPrimaryDark" targetApi="23">@android:color/transparent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="customBackgroundColor">@android:color/transparent</item>
<item name="customPrimaryTextColor">#000000</item>
</style>
This code changes the background color of the StatusBar, but I needs to change the color of the text and icons on the StatusBar.
if (Build.VERSION.SDK_INT >= 21) {
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(this.getResources().getColor(R.color.primary_color));
}
Upvotes: 1
Views: 2817
Reputation: 40830
As per documentation: you need to use WindowInsetsController
to set setAppearanceLightStatusBars
which changes the foreground color of the status bars (icons & text):
new WindowInsetsControllerCompat(getWindow(),
getWindow().getDecorView()).setAppearanceLightStatusBars(true);
UPDATE
No need to the below, also they have deprecated APIs:
if (Build.VERSION.SDK_INT >= 21) {
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
To make the status bar light & icons/text dark on API Level 30:
Method 1: Programmatically:
new WindowInsetsControllerCompat(getWindow(),
getWindow().getDecorView()).setAppearanceLightStatusBars(true);
getWindow().setStatusBarColor( ResourcesCompat.getColor(getResources(), R.color.primary_color, null)); // Or Color.WHITE make it white
Method 2: In themes.xml:
add this in your app's theme:
<item name="android:windowLightStatusBar">true</item>
<item name="android:statusBarColor">@color/primary_color</item>
Upvotes: 6