使导航抽屉绘制在状态栏上,但仅当它处于打开状态时

Making Navigation Drawer to be drawn over status bar, but only when it is in open state

我的应用有 minSdkVersion 21targetSdkVersion 31。我希望导航抽屉被绘制在状态栏上,但只有当它处于打开状态时。

这就是当导航抽屉关闭时应用程序现在的样子,这就是我想要的样子:

但问题是当我打开抽屉时:

状态栏遮住了一部分,我想把抽屉画在状态栏上。

目前,我在主 activity 布局中有:

<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- The main content view -->
...

themes.xml中:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>

我怎样才能达到预期的效果?我尝试了不同的方法,但这里的方法最接近我想要的。除了描述的次要细节。

进一步研究该主题后发现我想在 post 中实现的东西没有意义,因为许多手机的状态栏中间都有一个摄像头区域并且在状态栏顶部渲染导航抽屉将使其部分被摄像头孔覆盖。