0

我使用此代码在我的活动的某些方法被调用后将汉堡按钮更改为向上按钮。禁用后,向上按钮无法使用抽屉指示器

mDrawerToggle.setDrawerIndicatorEnabled(false); 
getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

这是我onOptionsItemSelected

else if(item.getItemId() == android.R.id.home) { 
      ActionBar action = getSupportActionBar(); 
      action.setDisplayShowCustomEnabled(false); 
      action.setDisplayShowTitleEnabled(true); 
      mDrawerToggle.setDrawerIndicatorEnabled(true); 
      action.setDisplayHomeAsUpEnabled(false); 
     } 

然而,当我点击向上按钮,什么都没有发生。我哪里做错了?

回答

1

代替将代码移动到setToolbarNavigationClickListener解决问题。

mDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       ActionBar action = getSupportActionBar(); 
       action.setDisplayShowCustomEnabled(false); 
       action.setDisplayShowTitleEnabled(true); 
       action.setDisplayHomeAsUpEnabled(false); 
       mDrawerToggle.setDrawerIndicatorEnabled(true); 
      } 
     }); 
+0

太棒了!我一直在寻找这个解决方案。我甚至开始在我的应用程序中重新实现'appBar Drawer'逻辑交互。 – Mikhail

相关问题