actionBarDrawerToggle.setDrawerIndicatorEnabled(false) 后退箭头没有作用

actionBarDrawerToggle.setDrawerIndicatorEnabled(false) back arrow has no action

我使用导航抽屉,我想为内部片段禁用它。 我使用以下代码设置抽屉:

private void initSideMenu() {
        actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.Open, R.string.Close);

        drawerLayout.addDrawerListener(actionBarDrawerToggle);
        actionBarDrawerToggle.syncState();

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        binding.nv.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.menuData:
                        selectPersonalDataFragment();
                        break;
                    case R.id.menuBlogPosts:
                        closeDrawerAndNavigateTo(new BlogPostFragment(), true);
                        break;
                    case R.id.menuSettings:
                        closeDrawerAndNavigateTo(new BackgroundImageFragment(), true);
                        break;
                }
                return true;
            }
        });
    }

要禁用导航抽屉,我使用以下代码:

@Override
    public void setDrawerEnabled(boolean enabled) {
        Log.d(TAG, "setDrawerEnabled: " + enabled);
        if(enabled) {
            drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
            actionBarDrawerToggle.setDrawerIndicatorEnabled(true);
        } else {
            actionBarDrawerToggle.setDrawerIndicatorEnabled(false);
            actionBarDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onBackPressed();
                }
            });
        }
    }

汉堡图标变为后退箭头,但该箭头没有任何功能。那为什么我的听众不听呢?

经过大量尝试后我发现,我不必设置工具栏导航点击监听器,但必须覆盖 onSupportNavigateUp():

已更改 setDrawerEnabled():

@Override
    public void setDrawerEnabled(boolean enabled) {
        Log.d(TAG, "setDrawerEnabled: " + enabled);
        if(enabled) {
            drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
            actionBarDrawerToggle.setDrawerIndicatorEnabled(true);
        } else {
            actionBarDrawerToggle.setDrawerIndicatorEnabled(false);
        }
    }

新覆盖的 onSupportNavigateUp():

@Override
    public boolean onSupportNavigateUp() {
        onBackPressed();
        return true;
    }