Change the color of the navigation bar, Android

How to change the color / transparency of the navigation bar from black to the general color in devices before Lollipop (for example, the color of the status bar or action bar)?

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

+6
source share
3 answers

You can set the navigationBarColor attribute in the AppCompat theme or android:navigationBarColor in the 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

Please note that this does not work on Pre-Lollipop devices, since this function must be supported by the system, which is not available in Android 4.4 or later.

+10
source

Another software way:

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

Next, to change the color of the status bar, add the following line:

 window.setStatusBarColor(getResources().getColor(R.color.green)); 
+3
source

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> 

+2
source

Source: https://habr.com/ru/post/979997/


All Articles