How to change hamburger icon in Android (NavigationDrawer)

前端 未结 3 1993
别跟我提以往
别跟我提以往 2020-12-17 00:58

Before write this thread I have try to implement the different solution that I found in stackoverflow, but nothing work properly.

I\'m developing an Android applucat

相关标签:
3条回答
  • 2020-12-17 01:39
    Just use this :
    
    toolbar.post(new Runnable() {
                @Override
                public void run() {
                    Drawable d = ResourcesCompat.getDrawable(getResources(), R.mipmap.ic_launcher, null);
                    toolbar.setNavigationIcon(d);
                }
            });
    
    0 讨论(0)
  • 2020-12-17 01:41

    Simple and Elegant solution

    Place

    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.dashboardicon);//your icon here
    

    after

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer,toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();
    

    Overall Solution in Navigation Activity

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer,toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();
    
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.dashboardicon);
    
        navigationView= (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
    

    Note: It doesnt need any setNavigationOnClickListener()

    0 讨论(0)
  • 2020-12-17 02:01

    Disable drawer indicator for ActionBarDrawerToggle:

    toggle.setDrawerIndicatorEnabled(false);
    

    and then:

    toolbar.setNavigationIcon(R.drawable. ic_custom_drawer_icon);
    
    0 讨论(0)
提交回复
热议问题