How to hide default hamburger icon of Navigation v

2019-07-18 16:57发布

I need to hide the hamburger icon

enter image description here

enter image description here

This is my toolbar

I need to hide the default hamburger icon of navigation bar and load it from another button click.The navigation bar need to appear on the attachment icon click in my toobar and need to disappear when i click outside(anywhere).Can this be done ?

3条回答
小情绪 Triste *
2楼-- · 2019-07-18 17:54

This answer is same as @Yupi as answered. I am answering this again because posting this here will be easy to look and understand. If you are using supportActionBar, just do this to hide the Hamburger Icon.

getSupportActionBar().setDisplayHomeAsUpEnabled(false);

if you want to enable the Hamburger icon. Then

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
查看更多
劫难
3楼-- · 2019-07-18 18:00

if you are using ActionBarDrawerToggle then you can add a line

toggle.setDrawerIndicatorEnabled(false);

and opening and closing drawer you can write in your click event

if (drawer.isDrawerOpen(GravityCompat.START)) {
    drawer.closeDrawer(GravityCompat.START);
} else {
    drawer.openDrawer(GravityCompat.START);
}
查看更多
一夜七次
4楼-- · 2019-07-18 18:00

You can hide hamburger icon by this:

toolbar.setNavigationIcon(null);          // to hide Navigation icon
toolbar.setDisplayHomeAsUpEnabled(false); // to hide back button

If you have added the attachment icon manually (As an imageView inside a Toolbar) :

boolean isDrawerOpen = false;
imageViewAttachment..setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              if(!isDrawerOpen) {
                  mDrawerLayout.openDrawer(Gravity.LEFT);
                  isDrawerOpen = true;
              }
              else {
                  drawerLayout.closeDrawer(Gravity.END);
                  isDrawerOpen = false;
              }
            }
        });

Or, if you've added as a Menu item :

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.attachment:
                if(!isDrawerOpen) {
                  mDrawerLayout.openDrawer(Gravity.LEFT);
                  isDrawerOpen = true;
                }
                else {
                  drawerLayout.closeDrawer(Gravity.END);
                  isDrawerOpen = false;
                }
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
查看更多
登录 后发表回答