ActionBar was a great API for its time, but it does not scale well. Problems:

You could only have one ActionBar on screen at a time . What if you had two Fragments that each had an ActionBar and you want to display them side by side for a tablet?

. What if you had two Fragments that each had an ActionBar and you want to display them side by side for a tablet? “Why is my Fragment’s onCreateOptionsMenu() not being called…oh, I didn’t call setHasOptionsMenu(true)”.

You had to use a special theme to support the ActionBar. Why couldn’t it just be a normal view?

to support the ActionBar. Why couldn’t it just be a normal view? ActionBar does not support complex layouts. Toolbar does!

There is no need to call setSupportActionBar(toolbar)

Enter the Toolbar! It does everything the ActionBar does, and more. You can now create an action bar that is simply a View.

inflate your own menu via XML

set your own listener to handle item clicks

@SuppressLint("PrivateResource")

private void initToolbar() {

//inflate a menu via XML

toolbar.inflateMenu(R.menu.home_menu); //handle menuItem clicks

toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {

@Override

public boolean onMenuItemClick(MenuItem item) {

switch (item.getItemId()) {

case R.id.action_settings:

presenter.settingsClicked();

return true;

case R.id.action_search:

presenter.searchClicked();

return true;

case R.id.action_bookmark:

presenter.bookmarkClicked();

return true;

}



return false;

}

}); toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha); //back or home navigation

toolbar.setNavigationOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

getActivity().finish();

}

});



toolbar.setTitle("SomeTitle");

toolbar.setSubtitle("SomeSubtitle");

}

That’s it!