0

Hy i need a actionbardrawertoggle in right side on my app-bar if i use a navigation view.

First, navigation view in main ->

<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="end">

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<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_main"
    app:menu="@menu/activity_main_drawer" />

And i need this on right side if i swipe or clicked at a drawer toggle in toolbar (or appbar). But the drawer toggle not showing in right side because in left side. And if i clicked at the button, i get this exception

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

This exception is naturally because my layout in right / end side. So, my question is how can i allign this button in right side ? Or how can i solve this exception WITH right button ?

Here's my codes:

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close){

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            invalidateOptionsMenu();
            syncState();
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            invalidateOptionsMenu();
            syncState();
        }
    };
    drawer.setDrawerListener(toggle);
    toggle.setDrawerIndicatorEnabled(true);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    //add this line to display menu1 when the activity is loaded
    int firstMenu = R.id.nav_menu1;
    displaySelectedScreen(firstMenu);
    navigationView.setCheckedItem(firstMenu);
}

Curiosity is that, right to left swipe is working, navigation view is showed :) (But button doesn't work)

Can you help me ? :)

(Sorry my bad english!)

  • Im' so sorry. I edited this because is this not duplicated question. Or yet is this duplicated please tell for me similar to any question ? Thanks , and sorry again. – Dancs Berci Mar 22 '17 at 09:50
  • `ActionBarDrawerToggle` does not play well with `end`-aligned drawers, and it is always set on the home button, which means you can't align it to the other side. The solution is to not use `ActionBarDrawerToggle`. Use the replacement class in the answer on the linked duplicate. It's a drop-in replacement. – Mike M. Mar 22 '17 at 09:56
  • Oh, wait, are you asking which question is the duplicate? It's in the banner at the top of your post. You might've needed to refresh the page, but here's the link anyway: [Android navigation drawer toggle icon to right](http://stackoverflow.com/questions/39132398/android-navigation-drawer-toggle-icon-to-right). – Mike M. Mar 22 '17 at 10:00

0 Answers0