Newbiee Newbiee - 5 months ago 25
Android Question

drawer not covering actionbar

i want to open a drawer such that it covers the Actionbar. i tried it using a parent linear layout and inside it i defined toolbar and drawerLayout and is working fine but the thing is i cant see the menu item there.. that is i can open drawer only by swiping left to right on the screen. if i define toolbar outside of the linear layout than the menu is showing but the actionbar is not covered by drawer. how to achieve both of them simultaneously?
here is my xml file of Activity_main

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/white"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="variofitness.com.schedulekeeper.HomeActivity">
<include
android:id="@+id/toolbar_actionbar"
layout="@layout/toolbar_default"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:clickable="true" />

<fragment
android:id="@+id/fragment_drawer"
android:name="variofitness.com.schedulekeeper.Fragments.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>



Answer

try this way it will help

<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">


    <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/container_body"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />


    </LinearLayout>


    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:name="info.androidhive.materialdesign.activity.FragmentDrawer"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer" />

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