If your project uses style.xml
file to theme the project add this code to that file. Note that your app's theme must extend from the MaterialComponents
theme in order the coloring to work.
<style name="Theme.App" parent="Theme.MaterialComponents.*">
...
<item name="bottomNavigationStyle">@style/Widget.MaterialComponents.BottomNavigationView.Colored</item>
<item name="colorPrimary">COLOR_FOR_ICONS_AND_SURFACES</item>
<item name="colorOnPrimary">COLOR_FOR_ON_ICONS_OR_ON_SURFACES</item>
</style>
This will change the colors system-wide. If you want to apply it to only specific components then in your style.xml
again, you must define the color attributes as an overlay.
<style name="Theme.App" parent="Theme.MaterialComponents.*">
...
<item name="bottomNavigationStyle">@style/Widget.App.BottomNavigationView</item>
</style>
<style name="Widget.App.BottomNavigationView" parent="Widget.MaterialComponents.BottomNavigationView.Colored">
<item name="materialThemeOverlay">@style/ThemeOverlay.App.BottomNavigationView</item>
</style>
<style name="ThemeOverlay.App.BottomNavigationView" parent="">
<item name="colorPrimary">COLOR_FOR_ICONS_AND_SURFACES</item>
<item name="colorOnPrimary">COLOR_FOR_ON_ICONS_OR_ON_SURFACES</item>
</style>
The bottomNavigationStyle
defined in the Theme.App
will color all bottom navigation views by default. If you don't want this then you can apply the style to only particular BottomNavigationView
by defining the style
attribute of it. This will override the default style that was defined in the app theme.
<com.google.android.material.bottomnavigation.BottomNavigationView
...
style="@style/Widget.App.BottomNavigationView"
/>