Skip to content
Advertisement

How do I add a shadow beneath my action bar in Android?

I’m trying to get a shadow to appear beneath my action bar, but for some reason the shadow continually appears and begins at the very top of the screen, instead of beneath the action bar. I’m using a CustomView android.support.v7.widget.Toolbar action bar widget in each of my xml layout files. How can I get the shadow to properly appear beneath this action bar instead of at the top? Can I set some kind of divider equal to the height of this custom view before the shadow appears? Can we do something like set the height of the gradient to 50dp but only show the gradient in the last 5-10% of that height?

My theme:

JavaScript

Shadow drawable:

JavaScript

Toolbar:

JavaScript

Advertisement

Answer

Toolbar will have a shadow only in devices running on API 21 or higher. In order to achieve this effect you can add the property android:elevation="4dp" And it will work fine. Hope this helps

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement