我该如何在Android工具栏中删除最左边的导航抽屉菜单项?基本上,我想要以水平方式包含4张图像,仅此而已!
getSupportActionBar().setDisplayHomeAsUpEnabled(false)
这将移除导航抽屉图标。
yourActionBarDrawer.setDrawerIndicatorEnabled(false);
这将完全移除工具栏上的汉堡图标。
我的解决方案:
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.ACCEPT, R.string.CANCEL);
drawer.setDrawerListener(toggle);
toggle.syncState();
toggle.setDrawerIndicatorEnabled(false);
Toolbar toolbar = (Toolbar) findViewById(R.id.yourToolbarId);
那么
toolbar.setNavigationIcon(null);
参数 icon
要设置的Drawable,可以为null以清除图标
编辑:如果标题看起来没有对齐,请调用:
toolbar.getMenu().clear();
toolbar.setContentInsetsAbsolute(0,0);
final ActionBar ab = getSupportActionBar();
if (ab != null)
{
ab.setDisplayHomeAsUpEnabled(false);
}