Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Google has shown some nice ways that elevation effect are shown on Lollipop here.

android:elevation="2dp" 

for buttons,

android:stateListAnimator="@anim/button_state_list_animator" 

How can I mimic the elevation effect on pre-Lollipop versions without 3rd party library?

like image 470
AndroidDev Avatar asked Jun 11 '15 10:06

AndroidDev


2 Answers

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

like image 132
Ranjithkumar Avatar answered Sep 21 '22 21:09

Ranjithkumar


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

@Override public void setElevation(View view, float elevation) {  } 
like image 30
Gabriele Mariotti Avatar answered Sep 22 '22 21:09

Gabriele Mariotti