2

当我单击 UpButton(actionBar 的左箭头)时,它会打开我的抽屉菜单,并且 onOptionsItemSelected 方法不会收到任何内容。

如何防止我的抽屉菜单拦截 Upbutton 的点击?

AndroidManifest.xml

<activity
    android:name=".ChildActivity"
    android:theme="@style/AppTheme.NoActionBar"
    android:parentActivityName=".ParentActivity">

ChildActivity - OnCreate

    // Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
    this.setSupportActionBar(toolbar);

    ActionBar actionBar = this.getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Drawer Menu
    DrawerLayout drawer = (DrawerLayout) this.findViewById(R.id.main_drawer);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.drawer_open, R.string.drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) this.findViewById(R.id.main_navigation);
    navigationView.setNavigationItemSelectedListener(this);

ChildActivity - onOptionsItemSelected

public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        // This code is never executed
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

Ps:抽屉或 upButton 单独工作就可以了。我可以禁用/隐藏 ChildActivity 中的抽屉并在之后将其带回来,但我认为这不是正确的做法。

4

0 回答 0