I'm trying to display a Back button
on the Action bar
to move previous page/activity or to the main page (first opening).
And I can not do it.
my code.
ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(true);
the code is in onCreate
.
I know I'm a bit late, but was able to fix this issue by following the docs directly.
Add the meta-data tag to
AndroidManifest.xml
(so the system knows)Next, enable the back (up) button in your
MainActivity
And, you will be all set up!
Source: Android Developer Documentation
I know that the above are many helpful solutions, but this time I read this article (current Android Studio 2.1.2 with sdk 23) some method above doesn't work.
Below is my solution for sub-activity is MapsActivity
First, you need to add parentActivity in
like this :
Second, ensure that your sub-Activity extends
AppCompatActivity
, not FragmentActivity.Third, override
onOptionsItemSelected()
methodHope this will help!
well this is simple one to show back button
and then you can custom the back event at onOptionsItemSelected