更新时间:2022-12-29 08:44:27
您可以使用工具栏作为单机模式下,这意味着你不应该用你的工具栏为您mDrawerToggle构造的一部分,是这样的:
You can use the toolbar as Stand Alone mode, that means you should not use your toolbar as part of your mDrawerToggle constructor, this way:
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, null,
R.drawable.appbar, R.drawable.appbar)
此外,你应该手动抬高你的菜单
Also, you should inflate your menu manually
mToolbar = (Toolbar) findViewById(R.id.nav_toolbar);
mToolbar.inflateMenu(R.menu.base);
和删除setSupportActionBar(mToolbar);线code。
And remove the setSupportActionBar(mToolbar); line of code.
当然,你将不得不自己处理导航点击:
Of course, you will have to handle the navigation click by yourself:
mToolbar.setOnMenuItemClickListener(new OnMenuItemClickListener() ...
然后,您可以打开你的抽屉是这样的:
Then, you can open your drawer like this:
drawerButton = (BadgeDrawerButton) findViewById(R.id.badge_drawer_button);
drawerButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
mDrawerLayout.openDrawer(Gravity.LEFT);
}
});
希望这可以帮助。
Hope this may help.