Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change navigation bar color, Android

Tags:

java

android

xml

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?

like image 350
Marco Gagino Avatar asked Dec 21 '14 13:12

Marco Gagino


People also ask

How do I change the navigation color on my Android?

Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar. Step 3: In your MainActivity, add this code in your onCreate method.

How do I customize my navigation bar on Android?

From Settings, tap Display, and then tap Navigation bar. Make sure Buttons is selected, and then you can choose your desired button setup at the bottom of the screen. Note: This option will also affect the location you swipe when using Swipe gestures.


2 Answers

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.

like image 147
Floern Avatar answered Sep 20 '22 12:09

Floern


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));
like image 32
Terranology Avatar answered Sep 21 '22 12:09

Terranology