1

I'm trying to set a shadow on my navigation drawer after updating the support library but for some reason nothing is working and I'm stumped.

I came across this issue but it's solution is to just use setElevation which is also not working for me: https://code.google.com/p/android/issues/detail?id=184434

There really isn't much code to post but here's what I'm talking about for reference:

int currentapiVersion = android.os.Build.VERSION.SDK_INT;

if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) {
    mDrawerLayout.setDrawerElevation(25f);
} else {
    mDrawerLayout.setDrawerShadow(R.drawable.left_drawer_shadow, GravityCompat.START);
}

I'm using a ScrimInsetsFrameLayout but that shouldn't be causing the issue AFAIKT.

Any ideas?

Derek
  • 632
  • 2
  • 11
  • 29
  • Do you run app on lollipop+? – Oleksii Masnyi Oct 31 '15 at 13:09
  • Yeah tested on devices running marshmallow and a Samsung phone running 4.4, same results on both – Derek Nov 01 '15 at 23:50
  • Show us screenshot? Also you can try sample app: http://developer.android.com/shareables/training/NavigationDrawer.zip This app should have drawer shadow, I think, so you'll be able to test it on your devices. – krossovochkin Nov 02 '15 at 08:28
  • 2
    @krossovochkin that sample is out of date actually, I did take a look at that before asking – Derek Nov 02 '15 at 22:11

1 Answers1

5

What might have happened:

Since support lib 23 v21+ devices ignore custom drawables in this case. The the native built in elevation shadows are used. See: this issue

Here is the kicker though: transparent elements have no shadow.

By default the elevation shadow is drawn from the views background-outline. If the view has no background, the shadow won't show up.

If your view doesn't have its own background, using the outline Provider e.g.:

android:outlineProvider="bounds"

should do the trick. The doc can be found here ViewOutlineProvider. In short:

Interface by which a View builds its Outline, used for shadow casting and clipping.

Some more information and in-depth explanation is here: Android "elevation" not showing a shadow

Community
  • 1
  • 1
nacray
  • 81
  • 7
  • 1
    I'll try this for sure, my drawer layout definitely has a background but you never know – Derek Dec 15 '15 at 22:58