5

Im using new NavigationView from android support design library. It works fine but when I try to set it slide from right side it gets crashed with that exception:

java.lang.IllegalArgumentException: No drawer view found with gravity LEFT

My main layout:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/navigationDrawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include layout="@layout/activity_main_content" />

    <android.support.design.widget.NavigationView
        android:id="@+id/navigationView"
        style="@style/NavigationView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="right"
        app:headerLayout="@layout/header"
        app:menu="@menu/menu_drawer"/>

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

Can anyone know how to change this ? i try to change "layout_gravity" to "end" and it's give my the same error.

EDIT: full logcat:

java.lang.IllegalArgumentException: No drawer view found with gravity LEFT
        at android.support.v4.widget.DrawerLayout.openDrawer(DrawerLayout.java:1322)
        at android.support.v7.app.ActionBarDrawerToggle.toggle(ActionBarDrawerToggle.java:289)
        at android.support.v7.app.ActionBarDrawerToggle.access$100(ActionBarDrawerToggle.java:65)
        at android.support.v7.app.ActionBarDrawerToggle$1.onClick(ActionBarDrawerToggle.java:201)
        at android.view.View.performClick(View.java:4754)
        at android.view.View$PerformClick.run(View.java:19605)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:146)
        at android.app.ActivityThread.main(ActivityThread.java:5635)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
        at dalvik.system.NativeStart.main(Native Method)

activity_main_content.xml:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_content"
    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:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <include layout="@layout/toolbar" />

    </android.support.design.widget.AppBarLayout>


    <FrameLayout
        android:id="@+id/mainScreenFragmentContainer"
        style="@style/MainScreenFragmentContainer"
        android:layout_marginTop="?attr/actionBarSize"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.design.widget.CoordinatorLayout>
Fares
  • 139
  • 1
  • 5

3 Answers3

3
<android.support.design.widget.NavigationView
      android:id="@+id/nav_view"
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:layout_gravity="end"
      android:fitsSystemWindows="true"
      app:headerLayout="@layout/nav_header"
      app:menu="@menu/drawer_view" />

You should make sure that android:layout_gravity="end"

Denis Gordin
  • 892
  • 10
  • 22
Anantha Babu
  • 216
  • 2
  • 14
0

Use android:layout_gravity="end".

Bunny
  • 576
  • 4
  • 19
  • i try this one. After change "start" to "end" it gives me error: "No drawer view found with gravity LEFT" and menu icon is still on left side of toolbar :(. Any other idea how to change this ? – Fares Jul 15 '15 at 19:08
0
    import android.support.v4.widget.DrawerLayout;
private DrawerLayout drawerLayout;


drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
        drawerListener = new ActionBarDrawerToggle(this, drawerLayout,
                R.drawable.ic_drawer2, R.string.drawer_open,
                R.string.drawer_close) {
            @Override
            public void onDrawerClosed(View drawerView) {

                Toast.makeText(NavigationDrawerActivity.this, "on drawer close",
                        Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onDrawerOpened(View drawerView) {

                Toast.makeText(NavigationDrawerActivity.this, "on drawer open",
                        Toast.LENGTH_SHORT).show();
            }
        };
        drawerLayout.setDrawerListener(drawerListener);


@Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        drawerListener.syncState();
    }

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.

        int id  = item.getItemId();
        if(drawerListener.onOptionsItemSelected(item)){
            return true;
        }


        return super.onOptionsItemSelected(item);

    }
@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        drawerListener.onConfigurationChanged(newConfig);
    }
Vinayagam.D
  • 322
  • 3
  • 10