Change color StatusBar

2

How can I change the color of the StatusBar from the java class? For example, to change the color of the navigation bar (lower back, home and menu) would be like this:

  

getWindow (). setNavigationBarColor (getResources (). getColor (R.color.colorbarra_inf));

I would also be interested in color or style but I can not because AndroidManifest change the Theme AppTheme to Theme.AppCompat.Light to use the App blank and not black colors, and now changing the colorPrimary has no effect.

Style:

<resources>

    <!-- 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>
    </style>

</resources>

Thanks

    
asked by UserNameYo 31.01.2017 в 00:04
source

1 answer

3

An option if your app has at least API 21 is to add the android:statusBarColor property to your style, defining the desired color:

<!-- 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">@android:color/white</item>

</style>

It is important to comment that this would apply for all the Activities of your application that use the theme.

Another option is to use setStatusBarColor () ,

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();   
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.WHITE); //Define color blanco.
    }
    
answered by 31.01.2017 / 00:25
source