Reputation: 3052
I need to hide the hamburger icon
This is my toolbar
I need to hide the default hamburger icon of navigation bar and load it from another button click.The navigation bar need to appear on the attachment icon click in my toobar and need to disappear when i click outside(anywhere).Can this be done ?
Upvotes: 6
Views: 10242
Reputation: 6405
You can hide the hamburger icon by doing this:
toolbar.setNavigationIcon(null); // to hide Navigation icon
toolbar.setDisplayHomeAsUpEnabled(false); // to hide back button
If you have added the attachment icon manually (As an imageView
inside a Toolbar
) :
boolean isDrawerOpen = false;
imageViewAttachment..setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(!isDrawerOpen) {
mDrawerLayout.openDrawer(Gravity.LEFT);
isDrawerOpen = true;
}
else {
drawerLayout.closeDrawer(Gravity.END);
isDrawerOpen = false;
}
}
});
Or, if you've added as a Menu
item :
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.attachment:
if(!isDrawerOpen) {
mDrawerLayout.openDrawer(Gravity.LEFT);
isDrawerOpen = true;
}
else {
drawerLayout.closeDrawer(Gravity.END);
isDrawerOpen = false;
}
return true;
}
return super.onOptionsItemSelected(item);
}
Upvotes: 4
Reputation: 1358
if you are using ActionBarDrawerToggle
then you can add a line:
toggle.setDrawerIndicatorEnabled(false);
and opening
and closing
drawer you can write in your click event:
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
drawer.openDrawer(GravityCompat.START);
}
Upvotes: 17