how to hide up button in actionbar

前端 未结 4 1977
醉酒成梦
醉酒成梦 2021-01-02 17:16

I would like to do an edit mode, in the style of the tablet gmail app. If the user presses the edit button on the actionbar, than I would like to show him/her an action view

相关标签:
4条回答
  • 2021-01-02 17:36

    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
    }
    
    0 讨论(0)
  • 2021-01-02 17:45

    This worked for me, though its a slight change in the above mentioned solution

    android.support.v7.app.ActionBar actionBar = getSupportActionBar();
            if (actionBar != null) {
                actionBar.setHomeButtonEnabled(false); // disable the button
                actionBar.setDisplayHomeAsUpEnabled(false); // remove the left caret
                actionBar.setDisplayShowHomeEnabled(false); // remove the icon
            }
    
    0 讨论(0)
  • 2021-01-02 17:50

    You were almost there. To hide the icon/logo completely, use setDisplayShowHomeEnabled(false). The call you're using just removes the little arrow that indicates that the icon acts as an "up" button also.

    0 讨论(0)
  • 2021-01-02 17:50

    Though it's an older post, I would like to share an answer which worked for me.

    To hide the UP button in actionbar, use the following in OnCreateOptionsMenu:

    if (getSupportActionBar() != 
               getSupportActionBar().hide();
           }
    

    To remove the UP button in actionbar, use the following in OnCreateOptionsMenu:

    if (getSupportActionBar() != 
               getSupportActionBar().setDisplayHomeAsUpEnabled(false);
           }
    

    I hope it will help newbies.

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