Android appbarlayout elevation appears in status bar

故事扮演 提交于 2019-12-03 22:34:15

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!