When I click on my drawer toggle I get the following exception:
java.lang.IllegalArgumentException: No drawer view found with gravity LEFT
Ok. Let me make the things simple and clear here.
What is DrawerLayout?https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html
DrawerLayout
Acts as a top-level container for window content that allows for
interactive "drawer" views to be pulled out from the edge of the
window. Drawer positioning and layout is controlled using the android:layout_gravity
attribute on child views corresponding to which side of the view you
want the drawer to emerge from: left or right. (Or start/end on
platform versions that support layout direction.) 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.
DrawerLayout?, In Simple words:
android:layout_gravity="start" OR android:layout_gravity="left"
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
toolbar,R.string.navigation_drawer_open,
R.string.navigation_drawer_close)
mDrawerLayout.setDrawerListener(mDrawerToggle);
toggle() function
private void toggle() {
if (mDrawerLayout.isDrawerVisible(GravityCompat.START)) {
mDrawerLayout.closeDrawer(GravityCompat.START);
} else {
mDrawerLayout.openDrawer(GravityCompat.START);
}
}
/** Push object to x-axis position at the start of its container,
not changing its size.*/
public static final int START = RELATIVE_LAYOUT_DIRECTION | Gravity.LEFT;
Toggle() function calls the mDrawerLayout.openDrawer(Gravity.START)
/*** Open the specified drawer by animating it out of view. **
@param gravity Gravity.LEFT to move the left drawer or Gravity.RIGHT
for the right. * GravityCompat.START or GravityCompat.END may also
be used. */
public void openDrawer(@EdgeGravity int gravity) {
final View drawerView = findDrawerWithGravity(gravity);
if (drawerView == null) {
throw new IllegalArgumentException("No drawer view found with gravity " +
gravityToString(gravity));
}
openDrawer(drawerView);
}
layout_gravity="start” or left the No drawer view found with gravity LEFT is thrown.
I hope that helps. Happy Coding…