3

I am having some trouble adding elevation for android version < 21. Recently I found it easy to add elevation on card view but I could not achieve the same result for other views like picture view, toolbar, drawer layout, etc. Can anyone help me with it???

For example: if I want to add elevation to my drawer layout as per the material design, what should I do?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="@dimen/nav_header_height"
    android:background="@drawable/side_nav_bar"
    android:gravity="bottom"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:src="@drawable/ic_person_black_64dp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:text="Android"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="android studio" />

</LinearLayout>
Surendra Shrestha
  • 1,035
  • 12
  • 21

1 Answers1

5

One work around is that you can put all these view inside CardView

Just put LinearLayout inside CardView

For example :-

<android.support.v7.widget.CardView
    ....
    card_view:cardElevation="5dp"
    card_view:cardCornerRadius="0dp">


 <!--  other view that you want to elevate -->
 <DrawerLayout ../>  or <Toolbar  ---->

</android.support.v7.widget.CardView>
N J
  • 27,217
  • 13
  • 76
  • 96