0

I set navigation bar color in my app like this:

getWindow().setNavigationBarColor(ContextCompat
                        .getColor(MainActivity.this, R.color.my_color));

and after change fragment I want to reset navigation bar color(come back to default). How do this ? I want not set in my style android:navigationBarColor">@color/my_navigaton_bar_color< and when I want set default, call:

 getWindow().setNavigationBarColor(ContextCompat
                        .getColor(MainActivity.this, R.color.my_navigaton_bar_color));

P.S. I was try save in variable getWindow().getNavigationBarColor() but it always -1 , a also try decode value from android.R.attrs.navigationBarColor but it also doesn't work

M.Devan
  • 169
  • 2
  • 13
  • You have to set the color again, but you could use the primaryColor or colorAccent of your app that usually is where the color is from – javdromero Mar 18 '21 at 23:38

1 Answers1

2

This can be done inside styles.xml using

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

or

window.setNavigationBarColor(@ColorInt int color)

This image may also help you to indentify which color goes where enter image description here

You can find details: here and here

Junior Mourao
  • 273
  • 2
  • 7