2

When I click on the UpButton (actionBar's left arrow), it opens my drawer menu instead, and the onOptionsItemSelected method don't receive anything.

How can I prevent my drawer menu from intercepting the Upbutton's click?

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 : The drawer or the upButton, separately, work just fine. I can disable/hide the drawer in the ChildActivity and bring it back after, but I do not think it is the right thing to do.

Greelings
  • 4,964
  • 7
  • 34
  • 70
  • Why do you have a ActionBarDrawerToggle set if you don't plan on using it in conjunction with a NavigationDrawer? – asadmshah Dec 01 '15 at 10:51
  • I use a Drawer in conjunction with a NavigationDrawer to go down in the app navigation. It works fine. But i would like to use an upButton to go back to the main Activity. – Greelings Dec 01 '15 at 10:57

0 Answers0