简体   繁体   中英

ActionBarDrawerToggle customization

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

    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.

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));

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.

public type="style" name="Base.Widget.AppCompat.DrawerArrowToggle" id="0x7f0f00b2" />
</resources

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM