A box that does not overlap the action bar

I want to open the box so that it closes the action bar. I tried using the parent linear layout and inside it I defined the toolbar and drawerLayout and it works fine, but the thing is, I can’t see the menu item is .. that is, I can open the box only to scroll from left to right on the screen. if I define a toolbar outside the linear layout than the menu shows, but the action bar is not covered by the box. How to reach both of them at the same time? here is my xml file 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>

+4
source share
3 answers

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>
+4
Please modify your Xml:Put your action bar  inside the drawer or use drawer as parent layout: 
                            :   
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_all_courses_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    >


    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/parent_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.activlearn.ui.AllCoursesActivity">


        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">

            <include layout="@layout/home_tool_bar" />


        </android.support.design.widget.AppBarLayout>

        <include layout="@layout/content_all_courses" />

    </android.support.design.widget.CoordinatorLayout>


    <fragment
        android:name="com.activlearn.fragments.DrawerFragment"
        class="com.activlearn.fragments.DrawerFragment"
        android:layout_width="@dimen/drawer_width"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        tools:layout="@layout/fragment_drawer" />
</android.support.v4.widget.DrawerLayout>
+1

, . :

, DrawerLayout . DrawerLayout , ( , ), , .

, DrawerLayout . , , . :

<DrawerLayout>

    <LinearLayout> (or other type of layout)
        <Toolbar/>
        <content container/>
    </LinearLayout>

    <Navigation Drawer/>

</DrawerLayout>
+1

Source: https://habr.com/ru/post/1626322/


All Articles