android: how to remove the back/home button in the action bar

后端 未结 9 1494
一向
一向 2020-12-29 02:20

I am having difficulties trying to remove the back/home button from the action bar.

 getActionBar().setDisplayShowHomeEnabled(false);   //disable back button         


        
相关标签:
9条回答
  • 2020-12-29 02:59

    ElectronicGeeks answer is correct.

    For API lower than 11, Use:

    getSupportActionBar().setDisplayHomeAsUpEnabled(false);

    0 讨论(0)
  • 2020-12-29 03:03

    None of the suggested solutions works for me.

    But this one does:

    // Hide the back button
    mActionBar.setHomeAsUpIndicator(null);
    

    It is a kind of a hack (last resort solution), though, so showing the action bar again means setting its icon back again.

    0 讨论(0)
  • 2020-12-29 03:06

    If you're on API level 14 or above and are not using ActionbarSherlock, this code in onCreateOptionsMenu will disable the up button, remove the left caret, and remove the icon:

    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
    }
    

    source: https://stackoverflow.com/a/24967862/2887103

    0 讨论(0)
  • 2020-12-29 03:06

    This worked for me :)

        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(false);
    
    0 讨论(0)
  • 2020-12-29 03:09

    In case where you have used toolbar as Action bar:-

    Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar);

    Use the below code to hide navigation button:-

    toolbar.setNavigationIcon(null);

    0 讨论(0)
  • 2020-12-29 03:12

    Use getActionBar().setDisplayHomeAsUpEnabled(false) to remove the home button from the action bar.

    0 讨论(0)
提交回复
热议问题