Change ActionBarDrawerToggle icon android in toolbar?

核能气质少年 提交于 2019-11-30 18:37:18

For people who come across this SO question in future,

We have to disable drawer indicator

mDrawerToggle.setDrawerIndicatorEnabled(false);

and then set ToolBar's navigation button

 mToolbar.setNavigationIcon(R.drawable.navIcon);

P.S. after that we have to set Navigation click listner on toolbar and open NavigationDrawer manualy. like mToolbar.setNavigationOnClickListener :D

Qian Zhang

Try the code below:

getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);       
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_drawer);
mDrawerToggle.setDrawerIndicatorEnabled(false);

and open the drawer with

mImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            DrawerLayout drawer = findViewById(R.id.drawer_layout);
            drawer.openDrawer(Gravity.START);

        }
    });

You can set the menu icon using setHomeAsUpIndicator, pass a drawable to this method.

See code below:

    ActionBar ab = getSupportActionBar();
    ab.setHomeAsUpIndicator(R.drawable.ic_menu);
    ab.setDisplayHomeAsUpEnabled(true);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!