问题
To avoid confusion as to what the navigationbaractually is, here's a
As you can see, I've added a new color instead of the standard black color using:
<item name="android:navigationBarColor">@color/colorBackground</item>
But the icons are barely visible now, so I would like to change them into being black, or at least darker. I have searched SO and the webb but came up empty handed. Any ideas?
回答1:
You cannot change the color of the buttons yourself. However you can try to set the navigationbarlight to true. It should be noted that this is only available from API level 27.
windowLightNavigationBar added in API level 27
int windowLightNavigationBarIf set, the navigation bar will be drawn such that it is compatible with a light navigation bar background.
For this to take effect, the window must be drawing the system bar backgrounds with windowDrawsSystemBarBackgrounds and the navigation bar must not have been requested to be translucent with windowTranslucentNavigation. Corresponds to setting SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR on the decor view.
May be a boolean value, such as "true" or "false".
source
回答2:
You can tint the icons like this
Add this to your navigation view
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:itemIconTint="@drawable/bottom_nav_colors"
app:itemTextColor="@drawable/bottom_nav_colors"
app:menu="@menu/bottom_navigation" />
Define bottom_nav_colors like this
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/color1" android:state_checked="true" />
<item android:color="@color/color2" />
</selector>
you can change the colors in your code by changing the state like this..
BottomNavigationView mBottomNav = findViewById(R.id.navigation);
mBottomNav.getMenu().getItem(0).setChecked(true);
Or like this
mBottomNav.setSelectedItemId(0);
来源:https://stackoverflow.com/questions/50210070/how-do-i-change-the-color-of-the-navigation-bar-icons-android-studio