mikepenz/MaterialDrawer

Superflous status bar inset in targetSdkVersion 30+

Nohus opened this issue · 3 comments

Nohus commented

About this issue

Here is how my drawer should look like, and looked like so far:
image

After changing my targetSdkVersion from 29 to 30, this extra inset appears at the top:
image

I suspect it's there to prevent this:
image

Instead turning it into this:
image

This makes sense for normal items, but not in my case with a header. And of course I didn't expect my layout to change due to a targetSdkVersion update. It was working fine for a long time.

Details

  • Used library version: 8.4.2
  • Used support library version: appcompat 1.3.0
  • Used gradle build tools version: 7.0.2
  • Used tooling / Android Studio version: Arctic Fox 2020.3.1
  • Other used libraries, potential conflicting libraries: -

Checklist

This inset is not directly controlled by the library, but comes from the system.

The library has built in window inset handling, it's important to make sure the DrawerLayout is allowed to properly handle its insets for it to work.

Please have a look at the sample app, which also has an account header with a background image

Nohus commented

I tried reproducing this in the sample app. AccountHeaderView was displaying correctly, however I can't just use the account header because I don't use it for accounts and it's not possible to customize it enough so it looks like the layout I need. My header was a simple subclass of AbstractDrawerItem and added in the same as any other item. It still has the issue when added to the drawer in the sample app:
image

I found the solution is to not use the DrawerItem system, and instead instantiate my View myself and set it to MaterialDrawerSliderView.headerView. I wasn't able to check the docs when I found the issue, the library's website is just displaying a 404 now.

This doesn't really answer why the problem happened though. If this is the correct way, why was it working in targetSdkVersion < 30, and why did it stop in 30? I looked through the behavior changes in Android 11 and nothing seems relevant. Although I found a solution for my use case, it doesn't answer what happened here. Feel free to close the issue if you don't think it's worth investigating though; my issue is solved.

As you noted, the normal DrawerItems will not draw behind the StatusBar as this is usually not anticipated. Only the AccountHeader or HeaderView will go behind.

More advanced features like this are mainly highlighted either in the sample or can be seen by looking through the source.

There has been some changes to the insets handling in newer android versions, and I believe updating to target 30 may be triggering such.

Btw. the AccountHeader can be modified to not have any accounts and may only consist of 2 lines of text and the background.