Android appbarlayout elevation appears in status bar
Asked Answered
L

1

20

How do I get rid of the elevation in the status bar? If I set in AppbarLayout the app:elevation to 0dp the elevation doesn't appear anymore in status bar but also not below the AppbarLayout.

How do I just get the elevation under the AppbarLayout?

Here's a screenshot of what I mean: puush link, notice the shadow in the status bar :(

Thanks!

Latterday answered 15/11, 2015 at 23:22 Comment(4)
Can you post the Theme of your activity?Diffuse
Do you have draw behing statusbar flag?Sharl
I am not sure what you mean @NikolaDespotoskiLatterday
Amazed that so few people notice this glaring bug!Guardafui
G
25

Our concern is about shadow of AppBarLayout visible when status bar is transparent. Having an opaque status bar is not viable at all times. This happens on Lollipop & above only because of dynamic shadow rendering. On Marshmallow the wrong shadow looks even worse.

Best solution

Your root layout should have android:fitsSystemWindows="true" at all times, otherwise your UI will not draw behind status bar.

Now wrap the AppBarLayout inside another CoordinatorLayout which has android:fitsSystemWindows="false". This will prevent the shadow from overflowing into statusbar


Other workarounds (not recommended)

In your Style remove the statusBarColor:

<item name="android:statusBarColor">@android:color/transparent</item> 

So your theme would be:

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>

Also you can simply make app:elevation="0dp" on appbarlayout, but that removes the shadow on bottom also.

Guardafui answered 14/12, 2015 at 4:32 Comment(1)
Thanks a lot! It works.Here is a sample for reference for everyone else: gist.github.com/sahilshekhawat/00d24fb217f74f06fca27d133cb10d1aAllomorphism

© 2022 - 2024 — McMap. All rights reserved.