如何禁用汉堡图标变成箭头(导航组件)

How to disable Hamburger Icon turnung into arrrow (Navigation Component)

请帮帮我。
简介:我使用导航组件,单个 Activity 模式,通过底部导航菜单切换 3 个片段。我还有抽屉导航。
所有片段都是同一级别的(都是root,直接从bottm nav访问)
事情应该如何:对于所有片段,抽屉必须有一个带有汉堡包图标的工具栏。
问题:应用程序启动时,主页片段显示抽屉的标准汉堡包图标,没问题。但是当我切换到任何其他片段时,抽屉图标变成箭头图标。 此外,当按下箭头时,抽屉会从左侧滑动。这意味着它仍然用作显示抽屉菜单的按钮,但只是图标改变了
问题:当从底部导航菜单切换到另一个片段时,如何禁止将汉堡包图标转换为箭头图标?
文件: 导航图:

<navigation 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:id="@+id/nav_graph"
    app:startDestination="@id/bottom_nav_proposals"
    >
    <fragment
        android:id="@id/bottom_nav_proposals"
        android:name="com.base.ProposalsContainerFragment"
        android:label="fragment_proposals"
        tools:layout="@layout/fragment_proposals" />
    <fragment
        android:id="@id/bottom_nav_vehicles"
        android:name="com.base..DriversVehiclesFragment"
        android:label="Vehicles" >
    </fragment>
    <fragment
        android:id="@id/bottom_nav_drivers"
        android:name="com.bijov1apps.base.carrier.root.drivers.DriversVehiclesFragment"
        android:label="Drivers" >
    </fragment>
</navigation>

Activity:

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//initializing Navigation COmponent
       val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_carrier_root) as NavHostFragment
        val navController = navHostFragment.navController
//setting up toobar stuff
        val toolbar: Toolbar = findViewById(R.id.toolbar_root)
        toolbar.setupWithNavController(navController, drawerLayout)
//setting up navigation drawer stuff
        val drawerLayout:DrawerLayout = findViewById(R.id.drawer_layout)
        val navView: NavigationView = findViewById(R.id.nav_view)
        val toggle = ActionBarDrawerToggle(
            this, drawerLayout, toolbar, R.string.navigation_drawer_open, 
        R.string.navigation_drawer_close
        )
        drawerLayout.addDrawerListener(toggle)
        toggle.syncState()
        navView.setNavigationItemSelectedListener(this)
//setting up bottom navigation menu stuff
        val bottomNavigationView = findViewById<BottomNavigationView>(R.id.logisticBottomBar)
        bottomNavigationView.setupWithNavController(navController)
}

根据 Navigation Top App Bar documentation:

NavigationUI uses an AppBarConfiguration object to manage the behavior of the Navigation button in the upper-left corner of your app's display area. The Navigation button’s behavior changes depending on whether the user is at a top-level destination.

A top-level destination is the root, or highest level destination, in a set of hierarchically-related destinations. Top-level destinations do not display an Up button in the top app bar because there is no higher level destination. By default, the start destination of your app is the only top-level destination.

When the user is at a top-level destination, the Navigation button becomes a drawer icon if the destination uses a DrawerLayout. If the destination doesn't use a DrawerLayout, the Navigation button is hidden. When the user is on any other destination, the Navigation button appears as an Up button.

因此,如果您希望抽屉图标出现在所有顶级图标上,您需要创建一个 AppBarConfiguration 来列出这些目的地,并在您调用 setupWithNavController() 时使用它:

val appBarConfiguration = AppBarConfiguration(
    setOf(R.id.bottom_nav_proposals, R.id.bottom_nav_vehicles, R.id.bottom_nav_drivers), drawerLayout)
toolbar.setupWithNavController(navController, appBarConfiguration)

Navigation Drawer documentation on that same page 还特别指出,您在使用导航时 不应该 使用 ActionBarDrawerToggle。您必须删除所有这些代码。