Skip to content

Instantly share code, notes, and snippets.

@arvkmr
Created December 1, 2017 22:33
Show Gist options
  • Save arvkmr/261b875d07c481315efe29f0a6f04f7a to your computer and use it in GitHub Desktop.
Save arvkmr/261b875d07c481315efe29f0a6f04f7a to your computer and use it in GitHub Desktop.
Display back navigation button on toolbar / actionbar android
//////////////////////////////////
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
setSupportActionBar(toolbar);
ActionBar ab = getSupportActionBar();
if ((ab != null) && (getSupportParentActivityIntent() != null)) {
ab.setDisplayHomeAsUpEnabled(true);
}
}
//////////////////////////////////////////
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch(item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
break;
}
return true;
}
// Need to define the parent activity for the back button to actually show up.
<activity
android:name=".MainActivity"
android:theme="@style/RichPlayerLightTheme">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".LaunchActivity" />
</activity>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment