0

XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:f="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fffba9"
    android:orientation="vertical">

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/container_toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <include
                    android:id="@+id/toolbar"
                    layout="@layout/toolbar" />
            </LinearLayout>

            <FrameLayout
                android:id="@+id/content_frame"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            </FrameLayout>

        </LinearLayout>

        <ListView
            android:id="@+id/left_drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="#FFFFFF"
            android:choiceMode="singleChoice"
            android:divider="@android:color/darker_gray"
            android:dividerHeight="1dp" />

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

</RelativeLayout>

Code

mTitle = mDrawerTitle = getTitle();
mNavigationDrawerItemTitles = getResources().getStringArray(R.array.navigation_drawer_items_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);

setupToolbar();

DataModel[] drawerItem = new DataModel[1];

drawerItem[0] = new DataModel(R.drawable.connect, "exit");

getSupportActionBar().setHomeButtonEnabled(true);

DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.list_view_item_row, drawerItem);
mDrawerList.setAdapter(adapter);
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.setDrawerListener(mDrawerToggle);
setupDrawerToggle();

And

private class DrawerItemClickListener implements ListView.OnItemClickListener {

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        selectItem(position);
    }

}

private void selectItem(int position) {

    Fragment fragment = null;

    switch (position) {
        case 0:
            fragment = new ConnectFragment();
            break;
        case 1:
            fragment = new FixturesFragment();
            break;
        case 2:
            //fragment = new TableFragment();
            session.clear();
            Intent i = new Intent(Products.this, MainActivity.class);
            startActivity(i);
            finish();
            break;

        default:
            break;
    }

    if (fragment != null) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(mNavigationDrawerItemTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);

    } else {
        Log.e("MainActivity", "Error in creating fragment");
    }
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
public void setTitle(CharSequence title) {
    mTitle = title;
    getSupportActionBar().setTitle(mTitle);

}

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

void setupToolbar() {
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
}

void setupDrawerToggle() {
    mDrawerToggle = new android.support.v7.app.ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.empty, R.string.empty);
    //This is necessary to change the icon of the Drawer Toggle upon state change.
    mDrawerToggle.syncState();
}

Now when i click on icon ic_drwable to show menu say error No drawer view found with gravity LEFT

How can set navigation drawer to right of screen.

where i set android:layout_gravity="end" all things is ok but menu is left side of screen.

I want show drawer right to left of screen and

I want move toggle button to right side

  • Are you asking how to move the toggle to the other side, too? Or just how to make it work with the right-side drawer? – Mike M. Jan 23 '17 at 06:30
  • i want show drawer in right of screen.i change `end` gravity to start but say error No drawer view found with gravity LEFT –  Jan 23 '17 at 06:45
  • Yeah, `ActionBarDrawerToggle` doesn't work with `end`/`right` aligned drawers. Do you want to move the toggle button to the right side? Or leave it on the left side? – Mike M. Jan 23 '17 at 06:47
  • I want move toggle button to right side. –  Jan 23 '17 at 06:48
  • Have a look at [my answer here](http://stackoverflow.com/a/39136512). – Mike M. Jan 23 '17 at 06:50

0 Answers0