所以support V25
。我们有一个名为Bottom navigation的新组件。
按照设计指南,底部导航elevation
应为8dp
(https://material.io/guidelines/components/bottom-navigation.html#bottom-navigation-specs)
但是我无法将elevation
设置为它。
任何建议,例子将不胜感激。谢谢!
更新XML代码
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:elevation="8dp"
app:elevation="8dp"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@drawable/bottom_nav_color_state"
app:itemTextColor="@drawable/bottom_nav_color_state"
app:menu="@menu/bottom_navigation_main"/>
<FrameLayout
android:id="@+id/contentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/bottom_navigation"
android:background="#EDEDED"/>
答案 0 :(得分:36)
所以,现在(25.1.0)我们必须将BNV的android:background
设置为@android:color/white
以获得阴影。如果设置为其他颜色(即原色)
答案 1 :(得分:2)
我遇到了同样的问题,并且在我的情况下,OP建议的@android:color/white
是不可接受的。所以,因为我们不能&#34;#34;通过高程和自定义背景获取阴影我们需要破解它。
我的方法是在框架布局中添加阴影视图以模仿&#34;模仿&#34;标高。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:elevation="8dp"
app:elevation="8dp"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@drawable/bottom_nav_color_state"
app:itemTextColor="@drawable/bottom_nav_color_state"
app:menu="@menu/bottom_navigation_main"/>
<FrameLayout
android:id="@+id/contentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/bottom_navigation"
android:background="#EDEDED"/>
<some.kind.of.pager.or.other.content.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<View
android:id="@+id/shadow_view"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_gravity="bottom"
android:background="@drawable/shadow_gradient" />
</FrameLayout>
其中阴影视图的背景只不过是位于底部导航视图正上方的所有其他形状的形状渐变,如:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:endColor="@android:color/transparent"
android:startColor="#8f000000" />
</shape>
希望这有助于某人。
答案 2 :(得分:1)