Reputation: 449
I have a problem with my toolbar on one activity with 3 tabs. It works on all other pages of my app, but for some reason crashes when I try to click the menu on this page.
Here is the error:
java.lang.IllegalArgumentException: No drawer view found with gravity LEFT
at android.support.v4.widget.DrawerLayout.openDrawer(DrawerLayout.java:1618)
at android.support.v7.app.ActionBarDrawerToggle.toggle(ActionBarDrawerToggle.java:290)
at android.support.v7.app.ActionBarDrawerToggle.access$100(ActionBarDrawerToggle.java:64)
at android.support.v7.app.ActionBarDrawerToggle$1.onClick(ActionBarDrawerToggle.java:200)
at android.view.View.performClick(View.java:5697)
at android.view.View$PerformClick.run(View.java:22526)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Here is the xml for the layout:
<android.support.design.widget.CoordinatorLayout 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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="0dp">
<include android:id="@+id/app_bar"
layout="@layout/toolbar" />
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="48dp"/>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_below="@id/tab_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<fragment
android:name="com.bestworkouts.sheikoworkout.NavigationDrawerFragment"
android:id="@+id/fragment_navigation_drawer"
tools:layout="@layout/fragment_navigation_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer" />
</android.support.design.widget.AppBarLayout>
</android.support.v4.widget.DrawerLayout>
Thanks, hope someone can help me out!
Upvotes: 1
Views: 3123
Reputation: 401
java.lang.IllegalArgumentException: No drawer view found with gravity LEFT
i wanted the drawer to open from the right edge.
child layout widths /height did not work out for me, i had a line which was causing the whole illegal argument exception, removed the line
tools:openDrawer="Right"
and the argument exception went away
Upvotes: 0
Reputation: 2795
you can not put DrawerFragment inside child view of DrawerLayout You must have to provide drawer layout or drawer fragment as child view of Drawer layout. To solve your issue Simply put Fragment outside of AppbarLayout. just like that :
<android.support.design.widget.CoordinatorLayout 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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="0dp">
<include android:id="@+id/app_bar"
layout="@layout/toolbar" />
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="48dp"/>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_below="@id/tab_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.design.widget.AppBarLayout>
<fragment
android:name="com.bestworkouts.sheikoworkout.NavigationDrawerFragment"
android:id="@+id/fragment_navigation_drawer"
tools:layout="@layout/fragment_navigation_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
</android.support.design.widget.CoordinatorLayout>
Upvotes: 2
Reputation: 3353
You are missing to have a close tag for CoordinatorLayout at the end: </android.support.design.widget.CoordinatorLayout>
But, notice that DrawerLayout should be a top level layout.
From documentation:
To use a DrawerLayout, position your primary content view as the first child with a width and height of match_parent. Add drawers as child views after the main content view and set the layout_gravity appropriately. Drawers commonly use match_parent for height with a fixed width.
So i think you shouldn't put it (DrawerLayout) inside a CoordinatorLayout.
Android DrawerLayout - No drawer view found with gravity
Upvotes: 2