ActionBarDrawerToggle with AppCompatActivity and Toolbar Back button with Fragments

后端 未结 2 1220
长情又很酷
长情又很酷 2021-01-23 14:52

I am using the ActionBarDrawerToggle with NavigationView. My content is displayed using fragments.

I am following this stackoverflow question to get the back button pres

2条回答
  •  无人及你
    2021-01-23 15:28

    Remove this line

     if (mDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
    

    from onOptionsItemSelected() so it will look like this

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    
    switch (item.getItemId()) {
        case android.R.id.home:
            // doesn't reach here ever.
            return true;
        case R.id.action_x:
            // do something
            return true;
        case R.id.action_y:
            // do something
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
    }
    

提交回复
热议问题