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