76

Using API21+ Toolbar:

// Toolbar
Toolbar toolbar = new Toolbar(this);
toolbar.showOverflowMenu();

Would like to remove its shadow completely. setElevation(0) doesn't do anything since getElevation() already returns 0.

There is Material Design reference:

https://material.io/guidelines/layout/structure.html#structure-toolbars

There is Develop Reference:

https://developer.android.com/reference/android/widget/Toolbar.html

But I don't see any info related to the shadow. Toolbar

Question: how to remove/hide Toolbar shadow completely?

0leg
  • 13,464
  • 16
  • 70
  • 94

10 Answers10

147

Use app:elevation="0dp" instead of android:elevation on your toolbar. If it is not work, put your toolbar inside of a AppBarLayout and set app:elevation="0dp":

<android.support.design.widget.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:elevation="0dp">
            ...
</android.support.design.widget.AppBarLayout>
coder
  • 3,195
  • 2
  • 19
  • 28
92

Use attribute app:elevation="0dp" to your Toolbar or AppBarLayout to remove the shadow.

#. If you are using Toolbar only, then add attribute app:elevation="0dp" to Toolbar.

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:elevation="0dp"/>

#. If you are using AppBarLayout as a container of Toolbar, then add attribute app:elevation="0dp" to AppBarLayout.

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:elevation="0dp">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

OUTPUT:

enter image description here

UPDATE:

If you want to remove it programmatically then you can use below code:

getSupportActionBar().setElevation(0);

Hope this will help~

Ferdous Ahamed
  • 21,438
  • 5
  • 52
  • 61
41

Instead of android:elevation try app:elevation:

<android.support.design.widget.AppBarLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"       
    app:elevation="0dp">
</android.support.design.widget.AppBarLayout>
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user1517638
  • 972
  • 1
  • 10
  • 16
27

I have found solution myself:

getActionBar().setElevation(0);

More info:

https://developer.android.com/reference/android/app/Activity.html#getActionBar()

0leg
  • 13,464
  • 16
  • 70
  • 94
15

If you are using AppBarLayout in toolbar, you can use: app:elevation="0dp" instead of android:elevation in AppBarLayout

Boken
  • 4,825
  • 10
  • 32
  • 42
Mujeeb Rahaman T
  • 448
  • 3
  • 13
11
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
  appBarLayout.outlineProvider = null
}
drakeet
  • 2,685
  • 1
  • 23
  • 30
4
findViewById(R.id.appBarLayout).bringToFront();

Worked for me version issues I think Thanks Bjorn

in this question

Goodlife
  • 3,822
  • 2
  • 24
  • 23
2

Put this code in Fragment in which you want to hide the ToolBar.

@Override
public void onResume() {
    super.onResume();
    ((AppCompatActivity)getActivity()).getSupportActionBar().setElevation(0);
}
aslamhossin
  • 1,217
  • 12
  • 22
0

set "#00000000" to the backgroundColor of toolbar , remember that: if you use CoordinatorLayout and AppBarLayout ,you should remove the app:layout_behavior="@string/appbar_scrolling_view_behavior" of your contentView , I have made this elementary mistake.

gmyboy
  • 81
  • 1
  • 7
0

When you add elevation 0dp on your appbarlayout, toolbar will be completely diappeared. So that you should also add translationZ in your xml.

android:translationZ="0.1dp"
app:elevation="0dp"

Than it will look like ->

  <com.google.android.material.appbar.AppBarLayout
    android:id="@+id/toolbarLayout"
    android:background="@android:color/transparent"
    android:translationZ="0.1dp"
    app:elevation="0dp"
    android:theme="@style/ToolbarTheme"
    >

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       />
</com.google.android.material.appbar.AppBarLayout>