2

Hi I'm trying to apply a shadow to a linearlayout with the following code

if (<some condition>) layout.setElevation(4);

but this call requires API level 21 to work. How can I apply a shadow to layouts for devices with version < 5.0? Is it possible?

I know this is part of Material Design which is why I just want to know if there is a way to achieve something similar in previous versions, thanks :)

Mallika Khullar
  • 1,725
  • 3
  • 22
  • 37

1 Answers1

13

Use ViewCompat.setElevation(view, elevation);

Evgeni Roitburg
  • 1,958
  • 21
  • 33
  • What API level does this work back since? (are all the methods in ViewCompat from api level 4+ unless specified in the documentation?) – Ed Lee Jan 19 '17 at 01:53
  • 4
    The code of the call in **androidx.core.view.ViewCompat (1.0.1)** is literally the following: `public static void setElevation(@NonNull View view, float elevation) { if (Build.VERSION.SDK_INT >= 21) { view.setElevation(elevation); } }` So, I doubt it's going to have the desired effect. – Ammar Mohammad Jul 09 '19 at 22:49