Change status bar text color when primaryDark is white Change status bar text color when primaryDark is white android android

Change status bar text color when primaryDark is white


I'm not sure what API level your trying to target, but if you can use API 23 specific stuff, you can add the following to your AppTheme styles.xml:

<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 vice-versawhen 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>    <!-- Status bar stuff. -->    <item name="android:statusBarColor">@color/colorPrimaryDark</item>    <item name="android:windowLightStatusBar">true</item> </style>


you can do that programmatically like this answer

just add this

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);


it's very simple:

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);//  set status text darkgetWindow().setStatusBarColor(ContextCompat.getColor(BookReaderActivity.this,R.color.white));// set status background white

and vice versa:

getWindow().setStatusBarColor(ContextCompat.getColor(BookReaderActivity.this, R.color.black));View decorView = getWindow().getDecorView(); //set status background black decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); //set status text  light