如何将高程设置为底部导航

时间:2017-01-24 08:43:47

标签: android material-design

所以support V25。我们有一个名为Bottom navigation的新组件。

按照设计指南,底部导航elevation应为8dphttps://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"/>

3 个答案:

答案 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)

海拔高度已根据this提交在Android材料组件1.1.0(alpha)版本中得到修复。

修改

对于那些想知道的人,这是您添加新依赖关系的方法:

dependencies {
    // ...
    implementation 'com.google.android.material:material:1.1.0-alpha02'
    // ...
}

有关here的更多信息,请参见here

干杯!