Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appcompat v21 Toolbar elevation pre-lollipop

First off, I know that this question has been asked before, but it hasn't been answered before. I hope someone can give me an answer.

In my application, I use the Toolbar from Appcompat_v7 (API 21). This is my code:

<android.support.v7.widget.Toolbar     style="@style/DarkActionbarStyle"     android:id="@+id/toolBar"     android:layout_width="match_parent"     android:layout_height="@dimen/actionbar_height" /> 

And this is the ToolBar style I use:

<style name="DarkActionbarStyle" parent="@style/Widget.AppCompat.Toolbar">     <item name="android:background">?attr/colorPrimary</item>     <item name="titleTextAppearance">@style/ActionBarTitle</item>     <item name="android:elevation">2dp</item>     <item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>     <item name="theme">@style/ThemeActionBarDark</item> </style>  <style name="ThemeActionBarDark" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">     <item name="actionBarItemBackground">@drawable/btn_dark_orange</item>     <item name="selectableItemBackground">@drawable/btn_dark_orange</item> </style> 

The problem is, that elevation doesn't work pre-lollipop. So my question is: Is it possible to have a shadow under the ToolBar on pre-lollipop devices?

like image 459
Tristan Vanderaerden Avatar asked Nov 04 '14 19:11

Tristan Vanderaerden


1 Answers

This worked for me very well:

<android.support.v7.widget.CardView     xmlns:card_view="http://schemas.android.com/apk/res-auto"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:background="@color/primary"     card_view:cardElevation="4dp"     card_view:cardCornerRadius="0dp">      <android.support.v7.widget.Toolbar         android:id="@+id/toolbar"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:background="@color/primary"         android:minHeight="?attr/actionBarSize" />  </android.support.v7.widget.CardView> 
like image 185
Islam A. Hassan Avatar answered Oct 13 '22 22:10

Islam A. Hassan