Search code examples
javaandroidandroid-studioandroid-recyclerviewappbar

Android: Navigation/hamburger menu won't open after adding RecyclerView


My end goal is to create a simple material designed todo list. I'm only in the early stages, but I've hit an issue I can't seem to get through. When I add the recycler view to the main activity, the navigation menu won't show when I swipe from the left, or when I hit the hamburger menu. When I comment it out, it works fine. Does anyone know what the issue could be? I'm pretty sure it's something simple, but I've researched online and here on StackOverflow, and can't seem to come up with an answer. You all have been so helpful in the past, I'm hoping some magic can happen again!

I'm following the tutorial series here with a minor adjustment starting in video #6, where I want the recycler view in the main activity, instead of the navigation drawer: https://www.youtube.com/playlist?list=PLonJJ3BVjZW6CtAMbJz1XD8ELUs1KXaTD

Thanks!

Here is the layout in question:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_height="match_parent"
    android:layout_width="match_parent" >

    <!-- Navigation Drawer -->
    <LinearLayout
        android:id="@+id/drawer_layout_overall"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <!-- Include app_bar so the bar shows after drawer is opened -->
        <include
            android:id="@+id/app_bar"
            layout="@layout/app_bar" />

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

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

            <fragment
                android:id="@+id/fragment_navigation_drawer"
                android:name="cca.habitrpgnativeclient.com.NavigationDrawerFragment"
                android:layout_width="@dimen/nav_drawer_width"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                app:layout="@layout/fragment_navigation_drawer"
                tools:layout="@layout/fragment_navigation_drawer" />

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



    </LinearLayout>

    <!-- Tasks -->
    <!--<android.support.v7.widget.RecyclerView-->
        <!--android:id="@+id/tasks_layout"-->
        <!--android:layout_width="match_parent"-->
        <!--android:layout_height="wrap_content"-->
        <!--android:paddingTop="@dimen/app_bar_top_padding"-->
        <!--android:paddingLeft="@dimen/tasks_left_padding" />-->

</RelativeLayout>

Also, here is the method in question:

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

    // Setup toolbar
    toolbar= (Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Setup navigation menu
    NavigationDrawerFragment drawerFragment = (NavigationDrawerFragment)
                getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
    drawerFragment.setUp(((DrawerLayout) findViewById(R.id.drawer_layout)), toolbar);

    // Setup tasks
//        recyclerView  = (RecyclerView) findViewById(R.id.tasks_layout);
//        taskAdapter = new TaskAdapter(this, getTasks());
//        recyclerView.setAdapter(taskAdapter);
//        recyclerView.setLayoutManager(new LinearLayoutManager(this));

}

(Thanks for the edit, I added the other method as well)


Solution

  • Right now, your RecyclerView is overlaying the LinearLayout (containing your DrawerLayout) on the Z axis. Hence, your DrawerLayout is not going to receive any touch events, which is why your bezel swipe does not work. Apparently the app_bar <include> is a Toolbar, where I presume your hamburger is, and that too is being overlaid by the RecyclerView, which is why that does not work.

    The main UI of your activity goes where you have the FrameLayout. So, either replace the FrameLayout with the RecyclerView, or put the RecyclerView in the FrameLayout, or put the RecyclerView in a fragment that you load into that FrameLayout.