Bottom Navigation Icon color change

邮差的信 提交于 2020-01-04 05:13:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!