How to implement the Material-design Elevation for Pre-lollipop How to implement the Material-design Elevation for Pre-lollipop android android

How to implement the Material-design Elevation for Pre-lollipop


You can mimic the elevation on pre-Lollipop with a official method.

I achieve same effect using,

  android:background="@android:drawable/dialog_holo_light_frame"

My tested output:

enter image description here

reference - https://stackoverflow.com/a/25683148/3879847

Thanks to user @Repo..

Update : If you want change color of this drawable try @Irfan answer below ↓

https://stackoverflow.com/a/40815944/3879847


You can't mimic the elevation on pre-Lollipop with a official method.

You can use some drawables to make the shadow in your component. Google uses this way in CardView for example.

The ViewCompat.setElevation(View, int) currently creates the shadow only on API21+. If you check the code behind, this method calls:

API 21+:

  @Override    public void setElevation(View view, float elevation) {        ViewCompatLollipop.setElevation(view, elevation);    }

API < 21

@Overridepublic void setElevation(View view, float elevation) {}


You can either hack it using a card-view:

<android.support.v7.widget.CardView    xmlns:card_view="http://schemas.android.com/apk/res-auto"    android:id="@+id/btnGetStuff"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    card_view:cardCornerRadius="4dp"    card_view:cardBackgroundColor="@color/accent"    >    <!-- you could also add image view here for icon etc. -->    <TextView        android:id="@+id/txtGetStuff"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textSize="@dimen/textSize_small"        android:textColor="@color/primary_light"        android:freezesText="true"        android:text="Get Stuff"        android:maxWidth="120dp"        android:singleLine="true"        android:ellipsize="end"        android:maxLines="1"        /></android.support.v7.widget.CardView>

Or look at using this third party library: https://github.com/rey5137/Material (see wiki article on button https://github.com/rey5137/Material/wiki/Button)