Android 如何使抽屉越过动作栏?

Android 如何使抽屉越过动作栏?,android,drawerlayout,navigationview,Android,Drawerlayout,Navigationview,我在抽屉布局中添加了导航视图。问题是它位于操作和状态栏下。我希望它最好在两个栏上面,但我很高兴至少在动作栏上面 即使操作栏的背景色是透明的,但随着抽屉的打开,背景色也会变暗 以下是我的主要活动在xml中的样子: <?xml version="1.0" encoding="utf-8"?> <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/r

我在抽屉布局中添加了导航视图。问题是它位于操作和状态栏下。我希望它最好在两个栏上面,但我很高兴至少在动作栏上面

即使操作栏的背景色是透明的,但随着抽屉的打开,背景色也会变暗

以下是我的主要活动在xml中的样子:

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="@drawable/background"
    android:fitsSystemWindows="true"
    android:id="@+id/drawerLayout"
    >

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <FrameLayout
            android:id="@+id/fragmentContainer"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/sideMenu"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@drawable/navigation_menu_background"
        app:menu="@menu/navigation_menu"
        />

</androidx.drawerlayout.widget.DrawerLayout>

为了让这里的其他人更容易,可以在您现有的代码中添加它,这样其他人就可以复制粘贴它来尝试和帮助,只是一个简单的例子suggestion@a_local_nobody我添加了代码。为了让这里的其他人更容易,可能值得添加到您现有的代码中,以便其他人可以复制粘贴该代码以尝试提供帮助,只是一个suggestion@a_local_nobody我添加了代码。
class MainActivity : AppCompatActivity() {
    private var playlistFragment = PlaylistFragment.newInstance()
    private var streamFragment = StreamFragment.newInstance()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
//        window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        replaceFragment(playlistFragment)
        sideMenu.setNavigationItemSelectedListener { item ->
            handleNavigationItemTap(item)
            true
        }
    }

    private fun replaceFragment(fragment:Fragment){
        val fragmentTransaction = supportFragmentManager.beginTransaction()
        fragmentTransaction.replace(R.id.fragmentContainer, fragment)
        fragmentTransaction.commit()
    }

    private fun handleNavigationItemTap(item: MenuItem){
        when(item.itemId){
            R.id.playlistFragmentItem -> replaceFragment(playlistFragment)
            R.id.singleStreamItem -> replaceFragment(streamFragment)
        }
        drawerLayout.closeDrawer(GravityCompat.START)
    }
}