2017-01-24 25 views
7

所以通過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"/> 

+0

張貼含有底部導航你的XML代碼。 –

+0

check [this](https://code.google.com/p/android/issues/detail?id=226182&sort=-id%20-stars%20-status&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars %20Reporter%20Opened)和[this](http://stackoverflow.com/questions/40316411/bottomnavigationview-shadow-and-ripple-effect) –

+0

試試這個方法:http://stackoverflow.com/questions/41650778/android -bottom-navigation-bar-with-drop-shadow/41651284#41651284 –

回答

21

所以,現在(25.1.0),我們必須BNV的android:background設置爲@android:color/white有陰影。它不會顯示,如果你設置爲其他顏色(即你的主要顏色)

+0

作品就像一個魅力!謝謝! – Sjd

+2

確認解決方案。重要的(也是很奇怪的)部分是**必須**是'白色'顏色(來自'android' res或「custom」 - 但如果它必須是白色則不是那麼自定義)。沒有與黑色和其他任何工作... – snachmsm

+0

在這種情況下,如果將使用'app:elevation',它會在導航視圖底部添加一些陰影。如果我想在導航上添加陰影,我該怎麼辦? @NamNguyễn –

0

我有同樣的問題,並有一個@android:color/white作爲OP建議是不可接受的在我的情況。所以既然我們不能用高程和自定義背景獲得陰影,我們需要破解它。

我的方法是在框架佈局中添加陰影視圖以「模仿」高程。

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

希望這可以幫助別人。

0

This Works!請注意,您可以通過更改底欄的顏色:

"app:itemBackground="@color/white" 

,但你必須添加:

android:background="@android:color/white" 

完成:

<android.support.design.widget.BottomNavigationView 
    android:id="@+id/navigation" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:background="@android:color/white" 
    app:elevation="4dp" 
    app:itemBackground="@color/white" 
    app:itemIconTint="@color/grey" 
    app:itemTextColor="@color/grey" 
    app:menu="@menu/my_navigation_items" />