public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add((int groupId, int itemId, int order, charsequence title) .setIcon(drawable ID)
return true;
}
获取ID:
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch(item.getItemId())
{
case Menu.First+1 :
break;
case Menu.First+2 :
break;
}
return true;
}
val toolbar = findViewById<Toolbar>(R.id.toolbar)
val backButtonVisible = toolbar.navigationIcon != null
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
if(mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
//drawer is open
}
如果你的抽屉是打开的,那么在操作栏上会有返回图标;否则,在操作栏上会有菜单图标。