How do I add elevation (shadow) to my BottomNavigationView. It doesn't come by default

寵の児 提交于 2019-12-12 09:34:01

问题


I tried setting elevation from xml and programmatically both. But nothing works.


回答1:


It only works if you set white as android:background in the BottomNavigationView.

This is my code and it's working:

<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="@color/white"
    app:elevation="8dp"
    app:itemIconTint="@color/bottom_color_state"
    app:itemTextColor="@color/bottom_color_state"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.52"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:menu="@menu/bottom_navigation_main" />



回答2:


I got the solution. You need to add background attribute along with elevation else it wont show the shadow.




回答3:


This is the only solution that worked for me:

val background = bottomNavigation.background
if (background is MaterialShapeDrawable) {
    background.shadowCompatibilityMode = SHADOW_COMPAT_MODE_ALWAYS
}

as suggested here: https://issuetracker.google.com/issues/124153644#comment2



来源:https://stackoverflow.com/questions/40766722/how-do-i-add-elevation-shadow-to-my-bottomnavigationview-it-doesnt-come-by-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!