0

I'm trying to set the elevation of a AppBarLayout via code. When I do app:elevation in the XML it works without a hitch, however when I do

appBarLayout.setElevation(0);

It doesn't work.

My assumption is its calling the equivalent of android:elevation.

Any ideas?

spogebob92
  • 1,474
  • 4
  • 23
  • 32

1 Answers1

0

I dont know which api version you are using , but at least you must use Api v21 to set elevation. If you set elevation in pre lolipop you should get an error , but use it like that :

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
       appBarLayout.setElevation(0);
    }

If you use it on below v21 you get this error :

FATAL EXCEPTION: main
java.lang.NoSuchMethodError: android.support.design.widget.AppBarLayout.setElevation

The result : enter image description here

Yasin Kaçmaz
  • 6,573
  • 5
  • 40
  • 58