23

I'm implementing Bottom Navigation Bar in Android app using Google's support design library v25.1.0. Is there any way to add drop shadow effect, same as current Android native Google Photos app?

enter image description here

4 Answers 4

106

You can draw your own shadow just above the bottom bar using simple View and its background:

<View
    android:layout_width="match_parent"
    android:layout_height="4dp"
    android:layout_above="@id/bottom_bar"
    android:background="@drawable/shadow"/>

drawable/shadow.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:startColor="#1F000000"
        android:endColor="@android:color/transparent"
        android:angle="90" />
</shape>

Also, there are no compatibility issues if use this approach.

0
5

You can use elevation to add shadows to any view

<TextView
android:id="@+id/myview"
...
android:elevation="2dp"

android:background="@drawable/myrect" />

Refer this for more information

1
  • Does not work in my project: "Attribute 'elevation' is only used in API level 21 and higher (current min is 16)", would used that if it did work. Mar 9, 2017 at 11:33
5

For those using a CoordinatorLayout with the Bottom Navigation Bar (or BottomAppBar), you can use the following to attach a shadow above the bar:

<View
    android:layout_width="match_parent"
    android:layout_height="4dp"
    android:background="@drawable/shadow"
    app:layout_anchor="@+id/toolbar"
    app:layout_anchorGravity="top"/>

Obviously, replace the @+id/toolbar with the id of the Bottom Navigation Bar

3

For those using Material Component - this has been fixed by com.google.android.material:material:1.1.0-alpha09.

Available since 1.1.0-alpha05 : https://github.com/material-components/material-components-android/releases/tag/1.1.0-alpha05

Use android:elevation="4dp" to set elevation shadow.

Also, do not forget to set clipChildren="false" on your main layout, otherwise, the shadow will be overwritten.

2
  • 1
    Any documentation link? Aug 19, 2019 at 20:08
  • It did not work out
    – kondal
    Jun 3, 2022 at 2:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.