【问题标题】:Bottom Navigation Icon color change底部导航图标颜色变化
【发布时间】:2017-01-31 01:06:57
【问题描述】:

当我尝试用黑色背景更改底部导航图标颜色时,我使用的是 BottomNavigation this,它不会改变颜色。

 bottomNavigation.setAccentColor(Color.parseColor("#FFE4770A"));
 bottomNavigation.setInactiveColor(Color.WHITE);
 bottomNavigation.setBackgroundColor(Color.BLACK);

但是当我用背景尝试它时,它会改变图标颜色。

 bottomNavigation.setAccentColor(Color.parseColor("#FFE4770A"));
 bottomNavigation.setInactiveColor(Color.WHITE);

如何解决?它会根据颜色背景更改图标颜色。

【问题讨论】:

  • 尝试使用setDefaultBackgroundColor() 而不是setBackgroundColor()

标签: java android xml navigation navigation-drawer


【解决方案1】:

我有另一个解决方案,如果你想尝试使用 XML,

app:itemBackground="@color/white" --> 这可以用于底栏颜色 app:itemIconTint="@color/blue" --> 这可以用来改变图标颜色 app:itemTextColor="@color/blue" --> 这可以用来改变图标底部文字的颜色

XML源代码如下所示

<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" />

参考:图片

【讨论】:

  • app:itemIconTint="@color/blue" 非常感谢你:)
【解决方案2】:

根据ahbottomnavigation repo 的文档,setBackgroundColor() 将覆盖图标的强调色。

setBackgroundColor() 替换为setDefaultBackgroundColor()

 bottomNavigation.setDefaultBackgroundColor(Color.BLACK);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-11
    • 2022-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-27
    • 1970-01-01
    • 2023-03-09
    相关资源
    最近更新 更多