首页 > 解决方案 > 将高程添加到 BottomNavigationView

问题描述

这是我在 XML 中的底部导航栏的样子:

<android.support.design.widget.BottomNavigationView
      android:id="@+id/bottom_nav"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:background="@android:color/white"
      app:itemBackground="@color/primary"
      app:elevation="8dp"
      app:menu="@menu/main_activity_bottom_nav"/>

如果我删除app:itemBackground="@color/primary",海拔显示正确,但我添加回来的那一刻,它消失了。

标签: androidandroid-support-librarybottomnavigationview

解决方案


我认为问题不在于使用app:itemBackground属性,而在于您设置为 itemBackground 的颜色。

如果我将app:itemBackground颜色更改为白色,它可以正常工作,并且可以显示底部导航视图的上方和底部的阴影。但是如果我使用我的原色(蓝色),我只能在我的 BottomNavigationView 的底部看到阴影。

我认为解决此问题的最简单方法是创建自己的阴影并将其设置在您的 BottomNavigationView 上方。这很简单。这篇文章描述了你必须做什么。

如果您遇到一些问题,请在下面发表评论。

我希望这个答案可以帮助你!

祝你好运!!


推荐阅读