Remove Android Toolbar Navigation Drawer option

后端 未结 6 2008
一整个雨季
一整个雨季 2021-01-02 21:07

How can i remove the leftmost navigation drawer menu item on the Android Toolbar. Basically i wan\'t to contain 4 images in a horizontal fashion, Nothing else !

相关标签:
6条回答
  • 2021-01-02 21:36

    Use

    yourActionBarDrawer.setDrawerIndicatorEnabled(false);
    

    This will remove the hamburger icon on toolbar completely.

    0 讨论(0)
  • 2021-01-02 21:37

    My solution:

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.ACCEPT, R.string.CANCEL);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    toggle.setDrawerIndicatorEnabled(false);
    
    0 讨论(0)
  • 2021-01-02 21:50

    getSupportActionBar().setDisplayHomeAsUpEnabled(false)

    This should remove the navigation drawer icon

    0 讨论(0)
  • 2021-01-02 21:51

    Might be late but you can get the reference to the Toolbar:

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

    then

    toolbar.setNavigationIcon(null);
    

    Reference here: https://developer.android.com/reference/android/widget/Toolbar.html#setNavigationIcon(android.graphics.drawable.Drawable)

    Parameters icon
    Drawable to set, may be null to clear the icon

    EDIT: if the title doesn't look aligned call:

    toolbar.getMenu().clear();
    
    0 讨论(0)
  • 2021-01-02 21:54
        final ActionBar ab = getSupportActionBar();
        if (ab != null)
        {
            ab.setDisplayHomeAsUpEnabled(false);
        }
    
    0 讨论(0)
  • 2021-01-02 21:55

    To remove the totally unfashionable margin who have the toolbar in the left side for a posible navigation icon you should do:

    toolbar.setContentInsetsAbsolute(0,0);
    
    0 讨论(0)
提交回复
热议问题