6

How can I change the color/transparency of the Navigation Bar from black to a generic color in pre-Lollipop devices (e.g. the color of the status bar or of the action bar)?

Can I do it using AppCompat or is it only possible for SDK 21?

Marco Gagino
  • 101
  • 2
  • 2
  • 4
  • 1
    Check this [link](https://x.appgyver.com/categories/3-user-interface-and-design/contents/16-customizing-navigation-bar-appearance) – Hana Bzh Dec 21 '14 at 14:06
  • This (http://developer.xamarin.com/guides/android/user_interface/navigation_bar/Images/19_-_NavBar.png ) is the navigation bar I meant. – Marco Gagino Dec 21 '14 at 14:16

3 Answers3

10

You can set the attribute navigationBarColor in an AppCompat theme, or android:navigationBarColor in a native v21 theme.

<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
    ...
    <item name="navigationBarColor">#123456</item>
</style>

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

Note that this does not work on Pre-Lollipop devices, since this feature needs to be supported by the system, which is not the case on Android 4.4 or older.

Floern
  • 33,559
  • 24
  • 104
  • 119
4

Another programmatically way:

window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.DarkOrange));
window.setNavigationBarColor(getResources().getColor(R.color.red));

Further, to change your status bar color, add the following line:

window.setStatusBarColor(getResources().getColor(R.color.green));
Community
  • 1
  • 1
Terranology
  • 610
  • 9
  • 15
  • 4
    Thank you so much, window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); was the thing I was missing. – jds17 Mar 12 '16 at 01:14
3

style-v21

<resources>

<style name="Theme.DesignDemo" parent="Base.Theme.DesignDemo">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowTranslucentNavigation">true</item>//translucent
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:navigationBarColor">@android:color/transparent</item>
</style>

hedgehog
  • 637
  • 7
  • 8