Changing Navigation drawer icon on action bar android - android

I have created a NavigationDrawer in my app using the ActionBar.
As showed in the picture above I want to change the NavigationDrawer toggle button icon to something I want. How can I change it?
Here is my code:-
mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
// enabling action bar app icon and behaving it as toggle button
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.hamburger_button, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
) {
public void onDrawerClosed(View view)
{
getActionBar().setTitle(mTitle);
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle("Settings");
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}
If I try changing it to R.drawable.hamburger_button It still shows the default icon

To replace the drawer indicator icon with your own drawable(non animated) using the v7 ActionBarDrawerToggle, you can do the following:
//After instantiating your ActionBarDrawerToggle
mDrawerToggle.setDrawerIndicatorEnabled(false);
Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.your_custom_icon, getActivity().getTheme());
mDrawerToggle.setHomeAsUpIndicator(drawable);
mDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (mDrawerLayout.isDrawerVisible(GravityCompat.START)) {
mDrawerLayout.closeDrawer(GravityCompat.START);
} else {
mDrawerLayout.openDrawer(GravityCompat.START);
}
}
});

Try changing the icon manually by using setHomeAsUpIndicator() .
Like,
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.ic_drawer);
and
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(...){};
mDrawerToggle.setHomeAsUpIndicator(R.drawable.ic_drawer_toggle);

Please make sure you include these to sync the states of the icon properly.
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}

Here is a working solution:
setSupportActionBar(toolbar2);
toggle = new ActionBarDrawerToggle(this,drawerLayout,toolbar2, R.string.navigation_drawer_open,R.string.navigation_drawer_close);
bottomNavigationView.setOnNavigationItemSelectedListener(this);
navigationView=findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
toggle.syncState();
//------------To change Navigation drawer icon ---------------//
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_favorite_black_24dp);
this Youtube video helped
https://www.youtube.com/watch?v=biUaIO-N7Ew

mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.hamburger_button(This you the icon), //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
)

call super class methods of ActionBarDrawerToggle super.onDrawerClosed(view) and super.onDrawerOpened(drawerView) like
mDrawerToggle = new ActionBarDrawerToggle(...){
public void onDrawerClosed(View view)
{
super.onDrawerClosed(view);
//---your code
}
public void onDrawerOpened(View drawerView)
{
super.onDrawerOpened(drawerView);
//---your code
}
}

For me adding the setHomeAsUpIndicator worked.
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.custom_icon, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */
) {
public void onDrawerClosed(View view) {
getSupportActionBar().setTitle(mTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.custom_icon);

Under the initialization of ActionBarDrawerToggle write the following code:
toolbar.setNavigationIcon(R.drawable.ic_menu_camera);

First of all you should in manifest try this code :
android:icon="#drawable/ic_icon1"
This is image for total logo of your app
android:logo="#drawable/ic_drower"
This is image for action bar
After that in main-activity try this code :
actionBar.setDisplayUseLogoEnabled(true);

setSupportActionBar(yourToolbar);
yourToolbar.setNavigationIcon({yourDrawable});
Don't set Navigation Icon before setSupportActionBar()

Related

To close the Navigation Drawer on touch of screen

I am new to this Android. Here I got stuck with one problem that when I click
on Navigation Drawer item then it give other item and then on touch of screen then Navigation Drawer get closed but back button still there.
I put mDrawerLayout.ontouchlistener it does work but i want that icon back on click on screen. I does not want back button
When I click on category item inside Navigation Drawer:
Then I put another adapter with different ArrayList in ExpandableListView:
But when I touch on screen then it close Navigation Drawer but back icon is still there:
set
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(false);
inside your activity.
I checked in developers.android.com. They gave one small solution. Hope this works.
private ActionBarDrawerToggle mDrawerToggle;
...
private DrawerLayout mDrawerLayout;
public void onCreate(Bundle savedInstanceState) {
...
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close /* "close drawer" description */
) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getActionBar().setTitle(mTitle);
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getActionBar().setTitle(mDrawerTitle);
}
};
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle, if it returns
// true, then it has handled the app icon touch event
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle your other action bar items...
return super.onOptionsItemSelected(item);
}
...
}

Do not show navigation drawer when pressing drawerToggle

I have programmatically changed the hamburger icon to arrow in ActionBarDrawerToggle.
Obviously the navigation drawer opens up when pressing the arrow too.
How do I prevent the drawer opening up?
I already am able to make the arrow change back into hamburger icon. I just dont want the navigation drawer to open up when its in the arrow state.
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
public class HomeActivity extends ActionBarActivity implements OnClickListener
{
...
...
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close)
{
public void onDrawerClosed(View view)
{
super.onDrawerClosed(view);
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView)
{
super.onDrawerOpened(drawerView);
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
DrawerAdapter draweradapter = new DrawerAdapter(context);
lvDrawer.setAdapter(draweradapter);
...
...
}

ActionToggle image not showing

I am implementing ActionTogglebutton to show drawer.though drawer are showing on click of toggle button but image or nothing is shown on toggle button position
Here is my code
actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.drawable.kooveicon) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(getTitle());
getActionBar().setDisplayShowHomeEnabled(false);
getActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle("Closed");
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle("Browse Items");
invalidateOptionsMenu();
}
};
Update your code exactly like below:
actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
mDrawerLayout = (DrawerLayout) findViewById(R.id.my_drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mDrawerToggle.setDrawerIndicatorEnabled(true);
mDrawerLayout.setDrawerListener(mDrawerToggle);
and add another method onPostCreate() in your class [this is drawer indicator animation]
#Override
protected void onPostCreate(Bundle savedInstanceState)
{
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
Hope this helped!

Change Icon Of Navigation Drawer

I am having trouble with changing my navigation drawer icon to a custom one. I've currently had to implement the standard drawer icon which has 3 horizontal lines on top, but now I want to replace this with my custom drawer icon.
This is how my mDrawerToggle is at the moment:
mDrawerToggle=new ActionBarDrawerToggle(this,
mDrawerLayout,
R.drawable.app_icon,
R.string.drawer_open) {
// My code
};
Use below code,it's working for V7 ActionBarDrawerToggle
mDrawerToggle.setDrawerIndicatorEnabled(false);
mDrawerToggle.setHomeAsUpIndicator(R.drawable.your_custom_icon);
mDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (mDrawerLayout.isDrawerVisible(GravityCompat.START)) {
mDrawerLayout.closeDrawer(GravityCompat.START);
} else {
mDrawerLayout.openDrawer(GravityCompat.START);
}
}
});
Here is the sample code taken from
Creating a Navigation Drawer
Activity.class
public class MainActivity extends Activity {
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
...
public void onCreate(Bundle savedInstanceState) {
...
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close /* "close drawer" description */
) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getActionBar().setTitle(mTitle);
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getActionBar().setTitle(mDrawerTitle);
}
};
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle, if it returns
// true, then it has handled the app icon touch event
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle your other action bar items...
return super.onOptionsItemSelected(item);
}
...
}
This is main activity
final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
toggle.setDrawerIndicatorEnabled(false);
toggle.setToolbarNavigationClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
drawer.openDrawer(GravityCompat.START);
}
});
toggle.setHomeAsUpIndicator(R.drawable.menuicon);
You could use this format for your mDrawerToggle:
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.CUSTOM_ICON, // Navigation menu toggle icon
R.string.DRAWER_OPEN, // Navigation drawer open description
R.string.DRAWER_CLOSE // Navigation drawer close description
)
Change your drawable and make sure it is the same name as the one in the code.
This is the main layout file
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Listview to display slider menu -->
<ListView
android:id="#+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/white"
android:choiceMode="singleChoice"
android:divider="#color/black"
android:dividerHeight="1dp" />
</android.support.v4.widget.DrawerLayout>
This is the main Activity
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.menuicon, // nav menu toggle icon
R.string.app_name, // nav drawer open - description for
// accessibility
R.string.app_name // nav drawer close - description for
// accessibility
) {
public void onDrawerClosed(View view) {
// getActionBar().setTitle(mTitle);
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
// getActionBar().setTitle(mDrawerTitle);
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
finally at R.drawable.menuicon(you can give your image id) it will work.

How to replace the hamburger icon used for ActionBarToggle on Android Toolbar with a custom drawable?

I have implemented a basic ActionBarDrawerToggle using the new Toolbar in Android 5.0.
However, I am unable to figure out how to change the default hamburger icon that is supplied.
From the android documentation it says that "the given Activity will be linked to the specified DrawerLayout and the Toolbar's navigation icon will be set to a custom drawable... This drawable shows a Hamburger icon when drawer is closed and an arrow when drawer is open. It animates between these two states as the drawer opens."
I currently have this all working correctly with the following code, however I want to replace the default supplied hamburger with my own drawable.
Here is my current code:
MainActivity.java
#InjectView(R.id.main_activity_toolbar)
Toolbar mToolbar;
#InjectView(R.id.main_activity_drawer_layout)
DrawerLayout mDrawerLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.main_activity);
super.onCreate(savedInstanceState);
setSupportActionBar(mToolbar);
mToolbar.setNavigationIcon(R.drawable.navigation);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
This line:
mToolbar.setNavigationIcon(R.drawable.navigation);
doesn't seem to work.
Is this possible to do? Thanks!
ActionBarToggle Documentation - https://developer.android.com/reference/android/support/v7/app/ActionBarDrawerToggle.html
You can use the toolbar as Stand Alone mode, that means you should not use your toolbar as part of your ActionBarDrawerToggle constructor, you can achieve that using the below code:
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, null,
R.drawable.appbar, R.drawable.appbar)
(Note how the toolbar instance is not being sent to the ActionBarDrawerToggle constructor)
Also, you should inflate your menu manually
mToolbar = (Toolbar) findViewById(R.id.nav_toolbar);
mToolbar.inflateMenu(R.menu.base);
And remove the setSupportActionBar(mToolbar); line of code.
Of course, you will have to handle the navigation click by yourself:
mToolbar.setOnMenuItemClickListener(new OnMenuItemClickListener() ...
Then, you can open your drawer like this:
drawerButton = (BadgeDrawerButton) findViewById(R.id.badge_drawer_button);
drawerButton.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
mDrawerLayout.openDrawer(Gravity.LEFT);
}
});
Hope this may help.
These two lines of code work for me:
mDrawerToggle.setDrawerIndicatorEnabled(false); //disable "hamburger to arrow" drawable
mDrawerToggle.setHomeAsUpIndicator(R.drawable.ic_drawer); //set your own
And then call this:
mDrawerToggle.syncState();
The default menu drawable for the ActionBarDrawerToggle is DrawerArrowDrawable.
You can subclass this to add custom functionality, like badges, like so:
public class BadgedDrawerArrowDrawable extends DrawerArrowDrawable {
/**
* #param context used to get the configuration for the drawable from
*/
public BadgedDrawerArrowDrawable(Context context) {
super(context);
setColor(context.getResources().getColor(R.color.colorAccent));
}
#Override
public void draw(Canvas canvas) {
super.draw(canvas);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.RED);
paint.setTextSize(60);
canvas.drawText("!", canvas.getWidth() - 60, 25, paint);
}
}
Usage:
actionBarDrawerToggle.setDrawerArrowDrawable(new BadgedDrawerArrowDrawable(activity));
My solution is by subclassing ActionBarDrawerToggle.
public class MyActionBarDrawerToggle extends android.support.v7.app.ActionBarDrawerToggle {
public MyActionBarDrawerToggle(Activity activity, final DrawerLayout drawerLayout, Toolbar toolbar, int openDrawerContentDescRes, int closeDrawerContentDescRes) {
super(activity, drawerLayout, toolbar, openDrawerContentDescRes, closeDrawerContentDescRes);
setHomeAsUpIndicator(R.drawable.drawer_toggle);
setDrawerIndicatorEnabled(false);
setToolbarNavigationClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
drawerLayout.openDrawer(Gravity.LEFT);
}
});
}
}
the thing that worked for me is that i just needed to call toolbar.setNavigationIcon(R.drawable.ic_camera_alt_24dp);
at the end of onCreate, or at least after mDrawerToggle = new ActionBarDrawerToggle...
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
final ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,drawer,toolbar,R.string.navigation_drawer_open,R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
toolbar.setNavigationIcon(R.drawable.ic_action_name);
as of Jan 2018, this is a working solution (at least for me):
//setSupportActionBar(toolbar)
val toggle = ActionBarDrawerToggle(this, drawer_layout, null, R.string.navigation_drawer_open, R.string.navigation_drawer_close)
toolbar.inflateMenu(R.menu.menu_main)
toolbar.setNavigationIcon(R.drawable.ic_menu)
toolbar.setNavigationOnClickListener {
drawer_layout.openDrawer(Gravity.START)
}
toolbar.setOnMenuItemClickListener {
true
}
drawer_layout.addDrawerListener(toggle)
toggle.syncState()
nav_view.setNavigationItemSelectedListener(this)
things to care:
setSupportActionBar should be commented out
ActionBarDrawerToggle is not taking a reference to toolbar
We should inflate menu ourself, and handle onClicks. onCreateOptionsMenu and onOptionsItemSelected will not be functioning.
Don't forget to call toggle.syncState()
As for v7 support library - you can create your own representation of DrawerArrowDrawable.
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
public void onDrawerClosed(View view) {
supportInvalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
supportInvalidateOptionsMenu();
}
};
mDrawerToggle.setDrawerIndicatorEnabled(true);
DrawerArrowDrawable drawerArrowDrawable = new DrawerArrowDrawable(this);
drawerArrowDrawable.setAlpha(1);
drawerArrowDrawable.setSpinEnabled(false);
drawerArrowDrawable.setDirection(DrawerArrowDrawable.ARROW_DIRECTION_LEFT);
drawerArrowDrawable.setColor(Color.BLACK);
mDrawerToggle.setDrawerArrowDrawable(drawerArrowDrawable);
Here's how I was able to finally get mine to work.
private Toolbar toolbar;
toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(R.drawable.ic_drawer);
mDrawerToggle = new ActionBarDrawerToggle(this,
mDrawerLayout,
toolbar,
R.string.drawer_open,
R.string.drawer_close) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
It turned out to be the
mDrawerToggle.syncState();
That finally got everything to work.
I think it is recommended to put the call to syncState() in the onPostCreate(...) lifecycle method.
#Override
public void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}

Categories

Resources