Created
December 1, 2017 22:33
-
-
Save arvkmr/261b875d07c481315efe29f0a6f04f7a to your computer and use it in GitHub Desktop.
Display back navigation button on toolbar / actionbar android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////// | |
@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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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