我正在尝试在“活动”的底部应用程序栏中创建导航视图,但是android.R.id.home无法正常工作。我已经将BottomAppbar对象设置为setSupportActionBar(mBottomAppBar),但是不起作用
mBottomAppBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()){
case R.id.emp_menu_home:
setFragment(empHomeFragment);
break;
case R.id.emp_menu_notif:
setFragment(notificationsFragment);
break;
case R.id.emp_menu_Inbox:
setFragment(inboxFragment);
break;
case R.id.emp_menu_cv:
setFragment(cvFragment);
break;
case android.R.id.home:
Toast.makeText(Main2Activity.this, "Home is click", Toast.LENGTH_SHORT).show();
NaviDrawerFragment naviDrawerFragment=new NaviDrawerFragment();
naviDrawerFragment.show(getSupportFragmentManager(),naviDrawerFragment.getTag());
break;
default:
return false;
}
return true;
}
});
答案 0 :(得分:0)
尝试添加:setHasOptionsMenu(true);在您的onCreate()中。
或
如果您使用的是新的工具栏和ActionbarDrawerToggle。您可以直接分配clickHandler。对于具有此抽屉工具栏的活动,我实现了一个界面,以使抽屉(如果在根目录下)处于启用状态,
@Override
public void enableDrawer(boolean enable) {
mDrawerToggle.setDrawerIndicatorEnabled(enable);
mDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Pop fragment back stack or pass in a custom click handler from the fragment.
}
});
}