Sandeep Kulkarni Sandeep Kulkarni - 16 days ago 5
Android Question

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 of
ResultActivity
. I want to maintain this hierarchy but want to get rid of back arrow.

enter image description here

M-Y M-Y
Answer

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
Comments