Abdelilah El Aissaoui
Abdelilah El Aissaoui

Reputation: 5340

Remove shadow toolbar below actionbar in blank activity

I've created a new project with a new blank activity using Android Studio and I'm trying to remove the shadow below the toolbar in >=API21. I've tried many things.

This works for < API21

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

This doesn't work for me in phone with >=API21:

getSupportActionBar().setElevation(0);
<item name="android:elevation">0dp</item>

I don't know what else I can try. Any help is appreciated. EDIT: I've tried everything from other questions like this but nothing worked.

Upvotes: 3

Views: 992

Answers (2)

Abdelilah El Aissaoui
Abdelilah El Aissaoui

Reputation: 5340

As @Vipul Asri said, I had to add app:elevation="0dp" but I was adding it to the wrong place. This works:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="android.teechart.steema.com.androiddemo.DashboardWebAnalytics">

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

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

    <include layout="@layout/content_dashboard_web_analytics" />



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

I was adding it in android.support.v7.widget.Toolbar but the correct place was in android.support.design.widget.AppBarLayout.

Upvotes: 1

user5713256
user5713256

Reputation:

This shadow is part of windowContentOverlay on APIs below LOLLIPOP (on LOLLIPOP it's @null).

When you work with Toolbar widget the toolbar isn't part of window decor anymore so the shadow starts at the top of the window over the toolbar instead of below it (so you want the windowContentOverlay to be @null). Additionally you need to add an extra empty View below the toolbar pre-LOLLIPOP with its background set to a vertical shadow drawable (8dp tall gradient from #20000000 to #00000000 works best). On LOLLIPOP you can set 8dp elevation on the toolbar instead.

Upvotes: 0

Related Questions