问题
I am using a BottomNavigation this when i try to change bottom navigation icon colors with black background its not change color.
bottomNavigation.setAccentColor(Color.parseColor("#FFE4770A"));
bottomNavigation.setInactiveColor(Color.WHITE);
bottomNavigation.setBackgroundColor(Color.BLACK);
But when i tried it with background it changes icon color.
bottomNavigation.setAccentColor(Color.parseColor("#FFE4770A"));
bottomNavigation.setInactiveColor(Color.WHITE);
How do fix it? it changes icon color with color background.
回答1:
According to the documentation of ahbottomnavigation repo, setBackgroundColor()
will override the accent colors for icons.
Replace setBackgroundColor()
with setDefaultBackgroundColor()
:
bottomNavigation.setDefaultBackgroundColor(Color.BLACK);
回答2:
I have an another solution, if you wanna try in XML,
app:itemBackground="@color/white" --> This can be use to bottom bar color app:itemIconTint="@color/blue" --> This can be used to change icons color app:itemTextColor="@color/blue" --> This can be used to change icon bottom text color
XML source code shown as below
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
app:itemBackground="@color/white"
app:itemIconTint="@color/blue"
app:itemTextColor="@color/blue"
app:menu="@menu/navigation" />
Ref :pic
来源:https://stackoverflow.com/questions/39639296/bottom-navigation-icon-color-change