How to change the color of the drawer icon in toolbar

5.8k Views Asked by At

Hi I am using the "android.support.v4.widget.DrawerLayout" for drawer. I want to change the color of the Drawer icon.Please some one tell me how I can do it.I share my code. Please have a look and suggest me what I have to do to change the icon color change.

 toolbar = (Toolbar) findViewById(R.id.tool_bar);
 setSupportActionBar(toolbar);
 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
 toolbar.setNavigationIcon(R.drawable.drawer);
 toolbar.hideOverflowMenu();
 getSupportActionBar().setTitle(null);
 ImageView img = (ImageView) findViewById(R.id.imgCourses);   
 mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView);
 mRecyclerView.setHasFixedSize(true);
 Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout);
 mAdapter = new MyAdapter(TITLES,NAME,EMAIL,PROFILE,this);  
 mRecyclerView.setAdapter(mAdapter); 
 mRecyclerView.setVerticalScrollBarEnabled(false);
 mLayoutManager = new LinearLayoutManager(this);
 mRecyclerView.setLayoutManager(mLayoutManager);  
 mDrawerToggle = new   ActionBarDrawerToggle(this,
                                             Drawer,
                                             toolbar,
                                             R.string.openDrawer,
                                             R.string.closeDrawer)
    {
        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);

        }

    };
    Drawer.setDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();
    Drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
3

There are 3 best solutions below

1
On BEST ANSWER

If you want to change color not image icon, you can use setColorFilter as below:

toolbar.getNavigationIcon().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY);

Hope to help you.

0
On

Why don't you use custom icon for your ToolBar rather than changing the color? Add your required icon to your drawable folder and use it like

toolbar.setNavigationIcon(R.drawable.ic_your_icon_name);
0
On

change drawer icon's color by customizing the drawer_toggle

mDrawerToggle.getDrawerArrowDrawable().setColor(getResources().getColor(R.color.grey));

happy coding :)