Android Lollipop Change Navigation Bar Color

Android lollipop change navigation bar color

It can be done inside styles.xml using

<item name="android:navigationBarColor">@color/theme_color</item>

or

window.setNavigationBarColor(@ColorInt int color)

http://developer.android.com/reference/android/view/Window.html#setNavigationBarColor(int)

Note that the method was introduced in Android Lollipop and won't work on API version < 21.

The second method (works on KitKat) is to set windowTranslucentNavigation to true in the manifest and place a colored view beneath the navigation bar.

android change navigation bar color

You can do it by adding this statement in styles

<item name="android:navigationBarColor">@color/theme_color</item>

or this in the main java

window.setNavigationBarColor(@ColorInt int color);

How to change the color of the navigation bar from an input method service?

Try using getWindow().getWindow() inside the InputMethodService instead of just the single getWindow() call.

It seems that the first getWindow() call returns a SoftInputWindow which is a type of Dialog, but you can call getWindow() again on it to get a PhoneWindow that is a proper Window, and that has the function you're looking for.

If you need a full example to look at, here's a code sample from Google's own codebase. I ran into this problem recently myself and this example is how I figured out how to do it.

How to change color of navigation bar (gesture mode)?

You can set the color of navigation bar like so:

val window: Window = this@MainActivity.window
window.navigationBarColor = ContextCompat.getColor(this@MainActivity, R.color.yourColor)

And you'll have to set your color in res/values/colors.xml:

<color name="yourColor">#0D0D0D</color>

Unable to change Navbar Color


While fixing another issue I had to change and minimum API level to
Lollipop and noticed that
<itemname="android:navigationBarColor">@color/theme_color</item>
started working when minimum API level is set to Lollipop.

So I think for some reason Xamarin requires to use use Minimum API version Lollipop for this to work

How to set the background color of system navigation bar to the one of the new Bottom Navigation bar in Material 3? (Android)

There is a new class in Material Components library in version 1.5.0 (specifically 1.5.0-alpha03) and up that solves this very problem, the SurfaceColors class.

To use it, call the getColor method on one of the constant values in the SurfaceColors enum for the desired color. Here is an example:

getWindow().setNavigationBarColor(SurfaceColors.SURFACE_2.getColor(this));

SURFACE_2 is what is used (or its equivalent) by BottomNavigationView. It works with and without Dynamic Coloring (including night mode). I have also observed this solution being used in the Files by Google app.

Here is a screenshot on Android 11

And here is a screenshot on Android 12.1 with Dynamic Coloring

If you're also curious about the exact shadow used by Google for the BottomNavigationView, it is a 5dp tall gradient drawable from #00000000 to #33333333.



Related Topics



Leave a reply



Submit