title: How to show the shadow of the ActionBar&Toolbar of the support library on all Android versions?
body: <p>This is a simple question:</p>
  
  <p>I use the new support library, which allows me to have a Toolbar instance and even set it as the actionBar of the activity (or use the default one).</p>
  
  <p>How do I customize the shadow being cast by the Toolbar (or the default ActionBar) ?</p>
  
  <p>I've tried to use "setElevation" (on both of them), but it didn't seem to do anything on Android Lollipop.</p>
  
  <p>Also, I can't find how to customize the shadow on pre-Lollipop versions. Is there maybe an API for this? or at least a drawable (I didn't find, even though I've tried) ? </p>
  
  <hr>
  
  <p>OK, I've managed to find the next things:</p>
  
  <p>For both Lollipop and pre-Lollipop, when your activity uses the normal AppCompat themes (like "Theme.AppCompat.Light" for example) , the shadow should look well.</p>
  
  <p>However, when you use "setSupportActionBar" (and use an appropriate theme, like "Theme.AppCompat.Light.NoActionBar" for example) , you will have some issues with the shadow.</p>
  
  <p>For pre-Lollipop, you can put a FrameLayout below the toolbar, that will look exactly like the one used for the normal themes, as such:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;android.support.v7.widget.Toolbar
          android:id="@+id/toolbar"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:minHeight="?attr/actionBarSize"
          app:theme="@style/ThemeOverlay.AppCompat.ActionBar" /&gt;
  
      &lt;FrameLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_below="@+id/toolbar"
          android:foreground="?android:windowContentOverlay"
          android:visibility="@integer/action_bar_shadow_background_visibility" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/toolbar"
          android:text="@string/hello_world" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>You can use the FrameLayout as your content of the activity, or use what I've done. You can also set its visibility by putting integer 0 for pre-lollipop and 2 for Lollipop and above, as I've done with "action_bar_shadow_background_visibility".</p>
  
  <p>It's an ugly solution, but it works, but only for pre-Lollipop versions. </p>
  
  <p>In any case, I still couldn't find a way to show the shadow well for Lollipop, in case I use "setSupportActionBar". I tried using "setElevation" on the toolbar and the actionbar (using "getSupportActionBar", right after calling "setSupportActionBar") .</p>
  
  <p>I also don't get how to get the standard height of the actionbar , as I noticed that a lot of tutorial say to use "minHeight" for the toolbar. Would appreciate help for this too.</p>
  
  <p>Can anyone help me with this?</p>
  
  <p>Again, to make it clear, this is what I ask:</p>
  
  <ul>
  <li>for Pre-Lollipop, show the same shadow that's used on the support library for both Toolbar and ActionBar.</li>
  <li>Same for Lollipop (but use the one that Lollipop has)</li>
  <li>Extra: customize the shadow to be more "delicate" on Lollipop (and maybe customize it on all versions).</li>
  <li>Extra: why does the minHeight of the toolbar get a value of the action bar height, instead of the height itself?</li>
  </ul>
  
  <hr>
  
  <p>EDIT: OK, this is as far as I've done so far to mimic the shadow of Lollipop :</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;android.support.v7.widget.Toolbar
          android:id="@+id/toolbar"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:minHeight="?attr/actionBarSize"
          app:theme="@style/ThemeOverlay.AppCompat.ActionBar" /&gt;
  
      &lt;include
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_below="@+id/toolbar"
          layout="@layout/toolbar_action_bar_shadow" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/toolbar"
          android:text="@string/hello_world" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>res/layout/toolbar_action_bar_shadow.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:foreground="?android:windowContentOverlay" /&gt;
  </code></pre>
  
  <p><strong>res/layout-v21/toolbar_action_bar_shadow.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ImageView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:src="@drawable/msl__action_bar_shadow" /&gt;
  </code></pre>
  
  <p><strong>res/drawable-v21/res/layout/msl__action_bar_shadow.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android" &gt;
  
      &lt;!-- intended for lollipop and above --&gt;
  
      &lt;item&gt;
          &lt;shape
              android:dither="true"
              android:shape="rectangle" &gt;
              &lt;gradient
                  android:angle="270"
                  android:endColor="#00000000"
                  android:startColor="#33000000" /&gt;
  
              &lt;size android:height="10dp" /&gt;
          &lt;/shape&gt;
      &lt;/item&gt;
  
  &lt;/layer-list&gt;
  </code></pre>
  
  <p>It's not exactly the same, but it's similar.</p>
  
  <hr>
  
  <p>EDIT: I still don't know why it happens. I think the code I've written on the question is misleading, as all there is to do is to set a background. Yet on the app I'm testing it still doesn't help. The app I'm trying to fix has the toolbar above the navigation drawer.</p>
  
  <p>For a moment I thought that it might be because I've made a customized toolbar (which extends from Toolbar) and that changes its alpha value (according to the navigation drawer), but even if I use the normal toolbar and disable everything that's related to alpha, it still doesn't work. Also, not only that, but on a totally new project, I've tried to set a semi-transpared background for the toolbar, and it got a shadow according to the "setElevation" method.</p>
  
  <p>Now it's even harder for me to find the cause for this problem, because it seems it's not because of transparency and not because of a custom Toolbar class...</p>
  
  <p>Here's the layout of the activity that has the toolbar, in case this can help in any way:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;android.support.v4.widget.DrawerLayout
          android:id="@+id/activity_main__drawerLayout"
          android:layout_width="match_parent"
          android:layout_height="match_parent" &gt;
  
          &lt;FrameLayout
              android:id="@+id/activity_main__fragmentContainer"
              android:layout_width="match_parent"
              android:layout_height="match_parent" /&gt;
  
          &lt;include
              android:layout_width="240dp"
              android:layout_height="match_parent"
              android:layout_gravity="left"
              android:layout_marginTop="?attr/actionBarSize"
              layout="@layout/activity_main__sliding_menu" /&gt;
      &lt;/android.support.v4.widget.DrawerLayout&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical" &gt;
  
          &lt;com.app.ui.Toolbar
              android:id="@+id/activity_main__toolbar"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:background="?attr/colorPrimary"
              android:layoutDirection="ltr"
              android:minHeight="?attr/actionBarSize"
              app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
              tools:ignore="UnusedAttribute" /&gt;
  
          &lt;!-- &lt;include --&gt;
          &lt;!-- android:layout_width="match_parent" --&gt;
          &lt;!-- android:layout_height="wrap_content" --&gt;
          &lt;!-- layout="@layout/toolbar_action_bar_shadow" /&gt; --&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>