Reputation: 2772
Need help figuring out why my toolbar is overlapping the contents.
I have a toolbar layout here
toolbar.xml
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/AppTheme">
</android.support.v7.widget.Toolbar>
I then use this toolbar with a navigation drawer like so.
navigation_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="me.jlurena.yougothw.activities.base.NavigationDrawer">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/toolbar"/>
</LinearLayout>
<ListView
android:id="@+id/nav_list"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#ffeeeeee">
</ListView>
</android.support.v4.widget.DrawerLayout>
Finally, so I would only have to extend a NavigationDrawer.java I set up the toolbar in NavigationDrawer.java and extend it in every other activity I'll need. I then inflate it like so
public void inflateBaseLayout(Activity activity, int resLayoutId) {
LayoutInflater inflater =
(LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// Inflate Navigation Drawer in activity
View view = inflater.inflate(resLayoutId, null, true);
drawer.addView(view, 0); // Where drawer is the DrawerLayout from navigation_drawer.xml
}
What exactly am I doing wrong with the toolbar?
Upvotes: 2
Views: 888
Reputation: 2772
I fixed it. I had to put the DrawerLayout
and Toolbar
inside a container such as a LinearLayout
because DrawerLayout as the root hovers over (overlaps) other contents.
I changed my navigation_drawer.xml to this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_navigation_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar"/>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="me.jlurena.yougothw.activities.base.NavigationDrawer">
<ListView
android:id="@+id/nav_list"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#ffeeeeee">
</ListView>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
Upvotes: 1
Reputation: 62831
Place the ListView
into the LinearLayout
after the include for the toolbar. That should bring everything in order.
Upvotes: 2