In many apps (Calendar, Drive, Play Store) when you tap a button and enter a new activity, the icon in the title bar turns into a back button, but for the app I am making, i
Light-weighted version without using ActionBarActivity that still has the same bahaviors here:
public class ToolbarConfigurer implements View.OnClickListener {
private Activity activity;
public ToolbarConfigurer(Activity activity, Toolbar toolbar, boolean displayHomeAsUpEnabled) {
toolbar.setTitle((this.activity = activity).getTitle());
if (!displayHomeAsUpEnabled) return;
toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
toolbar.setNavigationOnClickListener(this);
}
@Override
public void onClick(View v) {
NavUtils.navigateUpFromSameTask(activity);
}
}
Usage: Put new ToolbarConfigurer(this, (Toolbar) findViewById(R.id.my_awesome_toolbar), true); in onCreate.