Search code examples
androiddrawerlayoutandroid-actionbaractivityactionbardrawertoggle

ActionBarDrawerToggle clickable through open drawer layout


I'm trying to implement a simple navigation drawer. For this I use the support libraries for DrawerLayout, ActionBarActivity and ActionBarDrawerToggle.This is how it currently looks. The problem is that the navigation drawer toggle is clickable when the drawer layout is opened. You can see that in this short youtube video. My question is how can I stop the toggle from being clickable while the drawer layout is opened ? Below is a part of the code for my

MainActivity.java

...
public class MainActivity extends ActionBarActivity {

    private Toolbar toolbar;
    private ActionBarDrawerToggle drawerToggle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle("");
        setSupportActionBar(toolbar);


        DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.my_drawer_layout);
        drawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.ColorPrimaryDark));

        drawerToggle = new ActionBarDrawerToggle(this,drawerLayout,R.string.drawer_open, R.string.drawer_close);

        drawerToggle.syncState();
        drawerLayout.setDrawerListener(drawerToggle);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);

    }
    ...
}

and the layout for this activity

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/my_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <!-- The main content view -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <!-- Your main content -->
        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar"></include>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />
    </LinearLayout>

    <!-- The navigation drawer -->
    <com.username.navigationdrawertemplate.ScrimInsetsFrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/scrimInsetsFrameLayout"
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/ColorDrawerBackground"
        android:elevation="10dp"
        android:fitsSystemWindows="true"
        app:insetForeground="#4000">
    </com.username.navigationdrawertemplate.ScrimInsetsFrameLayout>
</android.support.v4.widget.DrawerLayout>

Solution

  • Put android:clickable="true" in navigation drawer layout