Skip to content Skip to sidebar Skip to footer

Unable To Create Navigation Drawer With Handle

I know that this question has been already asked here and here but still I am unable to create the navigation drawer with handle. I have used the class as mentioned below :: Drawer

Solution 1:

You need to put you Drawer and and other UI code inside a DrawerLayout. Consider this example:

<android.support.v4.widget.DrawerLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/drawer_layout"android:layout_width="match_parent"android:layout_height="match_parent" ><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"
        ><com.fscz.views.BounceViewPagerandroid:id="@+id/content_pager"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_centerInParent="true"
            /><com.fscz.views.CirclePageIndicatorandroid:id="@+id/content_indicator"android:layout_height="wrap_content"android:layout_width="wrap_content"android:padding="10dp"android:layout_centerHorizontal="true"android:layout_alignParentBottom="true"android:layout_marginTop="100dp"style="@style/link"
            /></RelativeLayout><LinearLayoutandroid:id="@+id/drawer"android:layout_width="240dp"android:layout_height="match_parent"android:layout_gravity="right"android:orientation="vertical"android:padding="20dp"android:background="@color/black_transparent"
        ><TextViewandroid:layout_width="240dp"android:layout_height="wrap_content"style="@style/text"android:text="@string/collections"android:paddingBottom="20dp"
            /><ListViewandroid:id="@+id/drawer_list"android:layout_width="240dp"android:layout_height="0dip"android:choiceMode="singleChoice"android:divider="@android:color/transparent"android:dividerHeight="0dp"android:layout_weight="1"
            /></LinearLayout></android.support.v4.widget.DrawerLayout>

The root element is an android.support.v4.widget.DrawerLayout. Inside there are 2 elements. A RelativeLayout and a LinearLayout. By convention the DrawerLayout assumes, that the first element is the actual layout of your activity/fragment/whatever. The second element is the drawer. Not the drawer handle but the UI you drag in from the side. You add the handle via Java code.

So.. in a nutshell. You try to add the the handle to the layout - in my case a RelativeLayout, in your case a FrameLayout - and not to the drawer. In your example the drawer has the id: left_drawer

Solution 2:

Try this in onClick in DrawerHandle class

if (mDrawerlayout.isDrawerOpen(Gravity.START)) {
                    mDrawerlayout.closeDrawers();
                } else {
                    mDrawerlayout.openDrawer(Gravity.START);
                }

Post a Comment for "Unable To Create Navigation Drawer With Handle"