Search code examples
androidandroid-statusbar

android: how to modify the font-color of status bar


how to modify the font-color of status bar? I find that some android applications can modify the font-color of status bar.I don't know how to do it.

Following are two pictures help to describe the question.Thanks!

the one after I open the application

the one before I open the application

The font-color of the one is white, while the other one is black.


Solution

  • Thanks to the release of Material Design you are able to change the color of status bar. First of all you have to tell your app to use material design through your manifest (you can use a material theme of your choice):

    android:theme="@android:style/Theme.Material.Light"
    

    To use material design your minSDK of your app have to be 21 (Lollipop) or alternatively you can use the v7 Support Libraries for the previous versions.

    https://developer.android.com/tools/support-library/features.html#v7

    Now, there are to ways to set the color of the Status bar. First, change it through the activity dynamically with the color you want every time (You have to declare color "blue" to your resources) - Inside you activity type:

    getWindow().setStatusBarColor(getResources().getColor(R.color.blue));
    

    And the second one is to extend the material design through your resources xml:

    <resources>
    <!-- inherit from the material theme -->
    <style name="AppTheme" parent="android:Theme.Material">
    <!-- Main theme colors -->
    <!--   your app branding color for the app bar -->
    <item name="android:colorPrimary">@color/primary</item>
    <!--   darker variant for the status bar and contextual app bars -->
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <!--   theme UI controls like checkboxes and text fields -->
    <item name="android:colorAccent">@color/accent</item>
    
    <!--  USE THIS FOR STATUS BAR COLOR -->
    <item name="android:statusBarColor">@color/blue</item>
    </style>
    </resources>
    

    https://developer.android.com/training/material/theme.html#ColorPalette

    For a quick test please use option one, hope i helped you!