Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create an android activity with back arrow as shown in the picture

Tags:

android

activity actionbar with back arrow similar to android material design menu

activity actionbar with back arrow similar to android material design menu

like image 286
karma Avatar asked Oct 26 '25 03:10

karma


1 Answers

You can add the following to your activity tag inside your manifest.xml file:

android:parentActivityName=".screens.MainActivity"

This will automatically place a back arrow inside your Activity and navigate to MainActivity when pressed.

Note This will only work in Android 4.1 or greater:

Beginning in Android 4.1 (API level 16), you can declare the logical parent of each activity by specifying the android:parentActivityName attribute in the element.

If your app targets Android 4.0 or before you should include the support library and add the following to your activity inside the manifest.xml:

<meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value=".screens.MainActivity" />

You will then need to allow Up navigation by adding this to your Activity:

getActionBar().setDisplayHomeAsUpEnabled(true);

For more information please see the Android docs.

like image 198
Leigh Avatar answered Oct 28 '25 15:10

Leigh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!