The toolbar and actionbaractivity under the ANDROID.SUPPORT.V7 package come with a back navigation button, just open it manually and let it show.
First look at the toolbar, page front code:
< Android.support.v7.widget.Toolbar Android:id = "@+id/toolbar" android:layout_width= "Match_parent" android:layout_height= "? attr/ Actionbarsize " android:background="? attr/colorprimary " app: Popuptheme= "@style/apptheme.popupoverlay"/>
If you want the back button to appear, you need to add the following code in the background
Getsupportactionbar (). setdisplayhomeasupenabled (true);
Of course, after adding this line of code is just a backward arrow only, after the click did not respond, need to continue to add listening events before the line, the default added button ID is fixed, Android. R.id.home, add the following listener events in the onoptionsitemselected
Case Android. R.id.home: finish (); break;
In fact, this is not the real return to the previous page, but the page is destroyed, thus displaying the previous page, that is, the page before the jump.
So actionbaractivity how to set it up, look at the following:
First, set the page to be returned in page A that you want to return.
Sethomebuttonenabled
The parentactivityname of page b in the manifest file is then set to page A, but this property is only available after API 16, which is used before the meta-data.
<meta-data android:name= "Android.support.PARENT_ACTIVITY" android:value= ". Mainactivity "></meta-data>
To display the Back button in page b, add the code
ActionBar actionbar=Getsupportactionbar (); Actionbar.setdisplayhomeasupenabled (true);
This displays a back arrow in the upper-left corner of the title bar of page B, which automatically returns to page a when clicked, and does not need to add additional listener events.
Summary: It seems that Actionbaractivity's back navigation is more convenient than toolbar, but so far, Google has not recommended the use of actionbaractivity, Now the new activity in as is inherited by Appcompatactivity, and as for why I don't know this beginner, I also try to realize toolbar's auto-rewind effect, But although toolbar also has the corresponding sethomebuttonenabled method and setdisplayhomeasupenabled, but it does not work, Google found after all said to add listening events, Did not find to say can achieve similar actionbaractivity effect, finally give up.
Android V7 Package toolbar and actionbaractivity for back navigation effects