42

I tried to remove the shadow below the toolbar with the Theme.AppCompat.Light.NoActionBar, using every recommendation of people who have ever answer it before, but no one worked. I tried

<item name="android:windowContentOverlay">@null</item>    

and

<item name="android:windowContentOverlay">@drawable/solid_line</item> ....

<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle">
<solid android:color="@color/accueil_color" />
<size android:height="15dp" />
</shape>

and with this,

android:elevation="0dp"

the shadow goes from the top of the screen but not disapear.

Have you any idea for totally remove this shadow line ??

oarfish
  • 4,116
  • 4
  • 37
  • 66
user3607438
  • 441
  • 1
  • 4
  • 5

10 Answers10

81

I'm not an expert but I run into the same problem just a few hours ago. So the idea here is that with AppCompat we have to manage the library attributes rather than Android attributes. In other words, 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"
    android:fitsSystemWindows="true"
    app:elevation="0dp">

    <android.support.v7.widget.Toolbar
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

EDIT :

I just tried another option without AppBarLayout. This way works perfectly fine for me, the shadow is completely gone. So I suspect the problem is in your other View. I don't think it's your ToolBar drops the shadow.

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    app:elevation="0dp" />
V-rund Puro-hit
  • 5,518
  • 9
  • 31
  • 50
DmitryO.
  • 973
  • 5
  • 8
  • Hum my xml is like this, i don't have android.support.design.widget.AppBarLayout, just the toolbar widget, – user3607438 Jul 18 '15 at 15:46
  • Can't comment on your answer due to lack of karma ). My best guess is your first view drops the shadow, not the toolbar. – DmitryO. Jul 18 '15 at 16:11
  • Arf ... I have tried to change elevation in android.support.v7.widget.Toolbar, and that change the location of the shadow, i think it is not the cause ... :/ Sorry That has worked :D thinks How to make resolved ? – user3607438 Jul 18 '15 at 17:24
  • I'm not 100% sure I understand the last comment... What about removing this entire attribute - android:elevation="@dimen/statusBarElevation" ? – DmitryO. Jul 18 '15 at 19:07
  • Sorry for my mistake, I had put android:elevation="0dp" in – user3607438 Jul 18 '15 at 19:09
  • One thing to be careful of: if you use `AppBarLayout` in conjunction with `CoordinatorLayout` and you set elevation to zero, it will be placed behind the "main content" in the `CoordinatorLayout` (since the main content likely has a zero elevation too) .. effectively hiding the Toolbar entirely. – tir38 Jun 24 '16 at 23:22
74

use app:elevation="0dp" instead of android:elevation

Krzysztof Wolny
  • 10,576
  • 4
  • 34
  • 46
Abdul Rehman
  • 2,313
  • 2
  • 15
  • 14
48

I had the same problem. Applying app:elevation="0dp" on android.support.design.widget.AppBarLayout solves the issue

Maher Abuthraa
  • 17,493
  • 11
  • 81
  • 103
Supritha P
  • 826
  • 8
  • 7
17

Add app:elevation="0dp" in AppBarLayout and shadow will be hide.

tiny sunlight
  • 6,231
  • 3
  • 21
  • 42
Vijay Vavdiya
  • 1,249
  • 13
  • 17
  • 1
    dont forget findViewById(R.id.appBar).bringToFront(); https://stackoverflow.com/a/41931318/2736039 – Ultimo_m Oct 01 '17 at 19:57
8

I had the same problem.

If your Toolbar is inside android.support.design.widget.AppBarLayout Adding app:elevation="0dp" on android.support.design.widget.AppBarLayoutwill solve your problem.

Else add app:elevation="0dp" on Toolbar.

<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"
android:fitsSystemWindows="true"
app:elevation="0dp">

<android.support.v7.widget.Toolbar
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

Hope it helps :)

Nihas Nizar
  • 619
  • 8
  • 15
6

Just use after the super.onCreate(savedInstanceState);

if(getSupportActionBar() != null)
{
   getSupportActionBar().setElevation(0);
}
Wasim K. Memon
  • 5,979
  • 4
  • 40
  • 55
Bède
  • 61
  • 1
  • 1
2

Just put your AppBarLayout inside of a LinearLayout on a separated XML file, and then, include this XML to your main XML.

1

@DmitryO Hum my xml is like this, i don't have android.support.design.widget.AppBarLayout, just the toolbar widget,

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:theme="@style/AppThemeAccueil">

    <View xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="@dimen/statusBarHeight"
        android:background="@color/accueil_colorDark"
        android:elevation="@dimen/statusBarElevation"/>

    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:popupTheme="@style/AppThemeAccueilToolbar"
        android:theme="@style/AppThemeAccueilToolbar"
        android:id="@+id/toolbarAccueil"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        materialdesign:elevation="0dp"
        android:elevation="0dp"
        android:outlineProvider="background"
        android:layout_marginTop="@dimen/appBarTopMargin" >

    </android.support.v7.widget.Toolbar>
</RelativeLayout>

Have I to had this ? (I think this will not change the result)

V-rund Puro-hit
  • 5,518
  • 9
  • 31
  • 50
user3607438
  • 441
  • 1
  • 4
  • 5
0

If your are not using Toolbar on the Layout and you have the default toolbar from AppCompactActivity this can help you

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

getSupportActionBar().setElevation(0);

At least it worked for me.

Regards,

JJeset BC
  • 23
  • 3
0

In Kotlin, use:

supportActionBar!!.elevation = 0.0f 

Regards!

Moises Portillo
  • 828
  • 8
  • 12