'android status bar font color is always white

I have the following theme for light mode in themes.xml:

<style name="Theme.MainTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="colorPrimaryDark">@color/colorPrimaryVariant1Light</item>
    <item name="android:statusBarColor">@color/colorPrimaryVariant1Light</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowLightStatusBar">true</item>
</style>

I definite night theme values in night/themes.xml as follows:

 <style name="Theme.MainTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="colorPrimaryDark">@color/colorPrimaryVariant1Dark</item>
    <item name="android:statusBarColor">@color/colorPrimaryVariant1Dark</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowLightStatusBar">false</item>
 </style>

The colors are white and black for colorPrimaryVariant1Light and colorPrimaryVariant1Dark respectively.

The background color of the status bar changes nicely, but the color of text and icons in the status bar remains white in both modes, so in light mode it is invisible on white background. How can this color be modified to be for example black in light mode? My minSdkVersion is 23 and I don't do any changes of translucency.



Solution 1:[1]

Use this set system status bar fond color dark

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_auth);
    setSystemBarDark(this);
}
public static void setSystemBarDark(Activity act) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        View view = act.findViewById(android.R.id.content);
        view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 logancodemaker