toolbar.setNavigationOnClickListener not working

I found the mistake we can't place toolbar outside of the DrawerLayout

here is how it looks like:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">



    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <!-- Framelayout to display Fragments -->
            <FrameLayout
                android:id="@+id/frame_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#2196F3"
                android:minHeight="?attr/actionBarSize"/>
        </FrameLayout>

        <!-- 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/list_background"
            android:choiceMode="singleChoice"
            android:divider="@color/list_divider"
            android:dividerHeight="1dp"
            android:listSelector="@drawable/list_selector" />

    </android.support.v4.widget.DrawerLayout>

</FrameLayout>

You should use the ActionBarDrawerToggle#setToolbarNavigationClickListener in your case.

From the Android Documentation:

When DrawerToggle is constructed with a Toolbar, it sets the click listener on the Navigation icon. If you want to listen for clicks on the Navigation icon when DrawerToggle is disabled (setDrawerIndicatorEnabled(boolean), you should call this method with your listener and DrawerToggle will forward click events to that listener when drawer indicator is disabled.

Another thing to remember is that

calling

toolbar.setNavigationOnClickListener()

before

setSupportActionBar(toolbar);

won't work.


I see that you are using the ActionBarDrawerToggle and hence setNavigationOnClickListener() is the wrong one. The right one is setToolbarNavigationClickListener(). This will make it behave like a toggle button.

mDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Log.d("TOU AQUI", "TOU AQUI");
    }
});