1

How to change icon for ActionBarDrawerToggle in android using AppCompat V7? Also, how can we specify params and padding etc for ActionBarDrawerToggle icon?

seema
  • 991
  • 1
  • 13
  • 27

3 Answers3

1
    Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
     setSupportActionBar(toolbar);
     toolbar.setNavigationIcon(R.drawable.ic_good);

Add these lines in your onCreate() method , also add

toolbar.setNavigationIcon(R.drawable.ic_good);

add this line after

toggle.syncstate();

and also in toggle listeners. Android will pick default icon every time you open or close the drawer, so its important to put this line in toggle listeners also.

Manish
  • 1,259
  • 3
  • 11
  • 20
1

If you want to change the toggle functionality you can set a custom toggle listener

DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(<Activity>, <DrawerLayout>, <Toolbar>, <String open>, <String close>){//override functionality};
drawerLayout.setDrawerListener(drawerToggle);

I don't think you can manually set the padding as this is a system button but you can manually set your own icon with its own padding

drawerToggle.setHomeAsUpIndicator(getResources().getDrawable(R.drawable.custom_drawable));
Marcus Hooper
  • 647
  • 7
  • 12
1

you have to disable drawer indicator

mDrawerToggle.setDrawerIndicatorEnabled(false);

and then set ToolBar's navigation button :

 mToolbar.setNavigationIcon(R.drawable.navIcon);

However, but in that case you will have to set Navigation click listner on toolbar and open NavigationDrawer manualy.

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
Bhavesh Patadiya
  • 25,740
  • 15
  • 81
  • 107