1

I am facing the issue in changing the colour of the status bar in lollipop devices .

Intially my status bar colour is in light grey i want to change the status bar colour into red. enter image description here

The styles using for the activity is

  <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">#A82A37</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>

The above style added in my application but there is no change in status bar colour.Please help me how to solve this.

Quick learner
  • 10,632
  • 4
  • 45
  • 55
Prabha Karan
  • 1,309
  • 3
  • 17
  • 35

2 Answers2

1

Use this

public static void changeStatusBarColor(Activity act, int colorRes) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        act.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        act.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        act.getWindow().setStatusBarColor(ContextCompat.getColor(act, colorRes));
    }

}
H4SN
  • 1,482
  • 3
  • 24
  • 43
0

Create a new folder under /res called /values-v21 and put this styles.xml in there.

MSpeed
  • 8,153
  • 7
  • 49
  • 61