Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Remove activity back Arrow

I created two blank activities in android studio and it looks like it adds back arrow by default. My MainActivity is parent ofResultActivity. I want to maintain this hierarchy but want to get rid of back arrow.

enter image description here

like image 716
skool99 Avatar asked Apr 18 '15 18:04

skool99


3 Answers

If you're on API level 14 or above and are not using ActionbarSherlock, this code in onCreateOptionsMenu should disable the up button;

ActionBar actionBar = getActionBar();
if (actionBar != null) {
    actionBar.setHomeButtonEnabled(false);      // Disable the button
    actionBar.setDisplayHomeAsUpEnabled(false); // Remove the left caret
    actionBar.setDisplayShowHomeEnabled(false); // Remove the icon
}

If you're using a support lib such as ActionbarSherlock, then use;

getSupportActionBar().setHomeButtonEnabled(false);      // Disable the button
getSupportActionBar().setDisplayHomeAsUpEnabled(false); // Remove the left caret
getSupportActionBar().setDisplayShowHomeEnabled(false); // Remove the icon
like image 53
Musa Avatar answered Oct 05 '22 05:10

Musa


getActionBar().setDisplayHomeAsUpEnabled(false);
like image 42
Bojan Kseneman Avatar answered Oct 05 '22 05:10

Bojan Kseneman


I know this is an old question but I came across this now and had to take some additional action to remove the back arrow.

So in addition to this piece of code as indicated the correct answer

getActionBar().setDisplayHomeAsUpEnabled(false);

you will also need to remove the parent-child relationship in the AndroidManifest.xml file . Your activity should not have the following entry

android:parentActivityName

Might help someone else who stumbles across this one.

like image 44
Anurag Phadke Avatar answered Oct 05 '22 04:10

Anurag Phadke