4

I'm trying for several hours now to change the background color of the system settings menu located on top of the actionbar. I searched on stack overflow and Google but i only found answers about the action bar itself. See the picture for extra clarification. Just like the Gmail app i want to change the color to dark red. Can some one post code how to achieve that? Also what is the actual name of the blue highlighted section in the picture?

Thank you!

enter image description here

sschrass
  • 6,331
  • 6
  • 39
  • 53
guicey
  • 531
  • 4
  • 14

2 Answers2

4

That area is called the status bar. Using the material theme, you can add this line to your styles xml to change the color.

<item name="android:colorPrimaryDark">@color/primary_dark</item>

Docs: https://developer.android.com/training/material/theme.html

To maintain compatibility, you should define your theme as such

<!-- extend one of the Theme.AppCompat themes -->
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
    <!-- customize the color palette -->
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
</style>

Then add this dependency in your build.gradle file

dependencies {
    compile 'com.android.support:appcompat-v7:21.0.+'
}

Docs: https://developer.android.com/training/material/compatibility.html

NOTE: While this will allow older devices to use the Material theme, it cannot modify the status bar color. See this blog post

There are a couple workarounds that people have come up with here

Community
  • 1
  • 1
Andrew Brooke
  • 11,633
  • 8
  • 32
  • 53
  • Is this the only solution available? My app target devices with API level 15+. I see this answer only works for devices with API level 21+. – guicey Oct 06 '15 at 15:01
  • @TheHagueCoder try to use `colorPrimaryDark` instead of `android:colorPrimaryDark`. `colorPrimaryDark` is definitely available on APIs lower 21 – Vasyl Glodan Oct 06 '15 at 15:03
  • Just adding to that last statement: you will have to include [`appcompat`](https://developer.android.com/tools/support-library/features.html#v7-appcompat) as a dependency of course. – MH. Oct 06 '15 at 15:13
1

To Support Pre Lollipop devices,you need to add add a compiled dependency of Appcombat v7 21 like below :

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
}
prat
  • 759
  • 5
  • 13