Reputation: 163
When I run the app and click on the toolbar icon I get the error as " No drawer view found with gravity LEFT"
this is my xml file
main.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" />
<android.support.v7.widget.RecyclerView
android:id="@+id/book_list_rv_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
<ListView
android:id="@+id/ListView1"
android:layout_width="241dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#333"
android:choiceMode="singleChoice"
android:divider="#666"
android:dividerHeight="1dp"
android:paddingLeft="15sp"
android:paddingRight="15sp" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
this id the code snippet of the activity java file activity file
Toolbar mToolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
// drawer
setSupportActionBar(mToolbar);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
mToolbar, R.string.app_name, R.string.app_name);
mDrawerLayout.setDrawerListener(mDrawerToggle);
Upvotes: 6
Views: 20210
Reputation: 21452
it may be related the way you try close drawer
mToolBar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mDrawerLayout.isDrawerOpen(Gravity.Start)) {
mDrawerLayout.closeDrawer(Gravity.Start);
} else {
mDrawerLayout.openDrawer(Gravity.Start);
}
}
for more reference
https://developer.android.com/reference/android/support/v4/view/GravityCompat.html#START
Upvotes: 8
Reputation: 1671
First set drawerlayout then set support action bar. Check following code.
Toolbar mToolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
mToolbar, R.string.app_name, R.string.app_name);
mDrawerLayout.setDrawerListener(mDrawerToggle);
setSupportActionBar(mToolbar);//modified(changed line)
Upvotes: 9
Reputation: 23655
Content and Drawer must be two children of the DrawerLayout. So change your layout like that:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" />
<android.support.v7.widget.RecyclerView
android:id="@+id/book_list_rv_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</LinearLayout>
<ListView
android:id="@+id/ListView1"
android:layout_width="241dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#333"
android:choiceMode="singleChoice"
android:divider="#666"
android:dividerHeight="1dp"
android:paddingLeft="15sp"
android:paddingRight="15sp" />
</android.support.v4.widget.DrawerLayout>
Upvotes: 10
Reputation: 2423
Content and drawer should be in different layouts, and drawer should have gravity left.
DrawerLayout
Contnet
Drawer
/DrawerLayout
Update your file like this,
<LinearLayout ....
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" />
<android.support.v7.widget.RecyclerView
android:id="@+id/book_list_rv_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</LinearLayout>
<ListView
android:id="@+id/ListView1"
android:layout_width="241dp"
android:layout_height="match_parent"
android:layout_gravity="left" //or start
android:background="#333"
android:choiceMode="singleChoice"
android:divider="#666"
android:dividerHeight="1dp"
android:paddingLeft="15sp"
android:paddingRight="15sp" />
</LinearLayout>
Upvotes: -1