工具栏不与导航抽屉一起显示。不在 android 工作室中,也不在设备中

Toolbar not showing with Navigation Drawer. Not in the android studio nor in the device

我在我的应用程序中使用了导航抽屉。我想在其中添加一个工具栏,但工具栏没有显示。它只是给出设计预览的尺寸估计。如图

我已经尝试了几乎所有可能的方法,但它不起作用。 提前致谢:)

xml 文件

 <?xml version="1.0" encoding="utf-8"?>

<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"
    tools:context="com.example.mrvirk.urduapp.MainActivity"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            />




    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="8">


        <android.support.v7.widget.GridLayout


            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:columnCount="2"
            app:rowCount="4">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="@color/green3"
                android:orientation="vertical"
                android:gravity="center"
                android:layout_margin="1dp"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1">

                <ImageView
                    android:id="@+id/learning"
                    android:layout_width="match_parent"
                    android:layout_height="@android:dimen/notification_large_icon_width"
                    android:scaleType="fitCenter"
                    android:src="@drawable/learning"
                    android:layout_gravity="center"
                    />


                <TextView
                    android:id="@+id/txtLearning"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/i_name"
                    android:textColor="@color/white"
                    android:textStyle="bold" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="@color/yellow"
                android:orientation="vertical"
                android:gravity="center"
                android:layout_margin="1dp"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1">


                <ImageView
                    android:id="@+id/acheivements"
                    android:layout_width="match_parent"
                    android:layout_height="@android:dimen/notification_large_icon_width"
                    android:scaleType="fitCenter"
                    android:src="@drawable/acheivements"

                    />


                <TextView
                    android:id="@+id/txtAcheivements"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/i_national"
                    android:textColor="@color/white"
                    android:textStyle="bold" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="@color/red"
                android:orientation="vertical"
                android:gravity="center"
                android:layout_margin="1dp"
                app:layout_columnSpan="2"
                app:layout_rowWeight="1"
                app:layout_columnWeight="1">

                <ImageView
                    android:id="@+id/quiz"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:scaleType="fitCenter"
                    android:src="@drawable/quiz" />

                <TextView
                    android:id="@+id/txtQuiz"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Quiz"
                    android:textColor="@color/white"
                    android:textStyle="bold" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="@color/blue2"
                android:orientation="vertical"
                android:gravity="center"
                android:layout_margin="1dp"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1">

                <ImageView
                    android:id="@+id/setting"
                    android:layout_width="match_parent"
                    android:layout_height="@android:dimen/notification_large_icon_width"
                    android:scaleType="fitCenter"
                    android:src="@drawable/setting" />

                <TextView
                    android:id="@+id/txtSetting"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Setting"
                    android:textColor="@color/white"
                    android:textStyle="bold" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="@color/tea"
                android:orientation="vertical"
                android:gravity="center"
                android:layout_margin="1dp"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1">

                <ImageView
                    android:id="@+id/share"
                    android:layout_width="match_parent"
                    android:layout_height="@android:dimen/notification_large_icon_width"
                    android:scaleType="fitCenter"
                    android:src="@drawable/share" />

                <TextView
                    android:id="@+id/txtshare"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Share"
                    android:textColor="@color/white"
                    android:textStyle="bold" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="@color/org"
                android:orientation="vertical"
                android:gravity="center"
                android:layout_margin="1dp"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1">

                <ImageView
                    android:id="@+id/about"
                    android:layout_width="match_parent"
                    android:layout_height="@android:dimen/notification_large_icon_width"
                    android:scaleType="fitCenter"
                    android:src="@drawable/about" />

                <TextView
                    android:id="@+id/txtAbout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="About"
                    android:textColor="@color/white"
                    android:textStyle="bold" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="@color/green3"
                android:orientation="vertical"
                android:gravity="center"
                android:layout_margin="1dp"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1">

                <ImageView
                    android:id="@+id/moreApps"
                    android:layout_width="match_parent"
                    android:layout_height="@android:dimen/notification_large_icon_width"
                    android:scaleType="fitCenter"
                    android:src="@drawable/moreapps" />

                <TextView
                    android:id="@+id/txtMoreApps"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="More Apps"
                    android:textColor="@color/white"
                    android:textStyle="bold" />

            </LinearLayout>
        </android.support.v7.widget.GridLayout>

    </LinearLayout>


    </FrameLayout>


    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:menu="@menu/drawer_view"
        app:headerLayout="@layout/nav_header"
        />

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

主工具栏 activity

Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.drawable.done);

月经

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mrvirk.urduapp">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
        <activity android:name="com.example.mrvirk.urduapp.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我的建议是替换 FrameLayout 并改用 RelativeLayout。事实上,RelativeLayout 应该包含 ToolbarLinearLayout.

<RelativeLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        />
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/toolbar"
    android:weightSum="8">
 ....
</LinearLayout>

LinearLayout 绘制在工具栏下方的事实是这样强制执行的:

android:layout_below="@+id/toolbar"

将您的 FrameLayout 更改为 LinearLayoutCoordinateLayout

如果你使用 LinearLayout 那么,

<LinearLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        />
    ........
</LinearLayout>

或者如果您使用 CoordinateLayout 那么,

<android.support.design.widget.CoordinatorLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    />
</android.support.design.widget.AppBarLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:weightSum="8">
    .......
</LinearLayout>
</LinearLayout>

Android 这样从上到下绘制视图; A-B-C- 是你的 DrawerLayout 中的 3 个各自的视图。现在作为工具栏的 A 是首先用参数宽度适合整体宽度和高度适合内容本身绘制的,B 是用宽度适合整体宽度和高度适合整体高度等绘制的,等等。这意味着您的 FrameLayout 在绘图序列中第二个绘制在您的 Toolbar 之上,但由于它被覆盖,您看不到它在那里,如果您将它放在下面,您的 Toolbar 将连续第二个绘制,因此您会看到它。

致谢:@Elltz

因此,只需将工具栏放在框架布局的末尾即可。 我修改了您的代码试试这个,现在让我知道工具栏是否显示:

<?xml version="1.0" encoding="utf-8"?>

<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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <FrameLayout

        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">



        <LinearLayout

            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="8">


            <android.support.v7.widget.GridLayout


                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:columnCount="2"
                app:rowCount="4">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:background="@color/green3"
                    android:orientation="vertical"
                    android:gravity="center"
                    android:layout_margin="1dp"
                    app:layout_columnWeight="1"
                    app:layout_rowWeight="1">

                    <ImageView
                        android:id="@+id/learning"
                        android:layout_width="match_parent"
                        android:layout_height="@android:dimen/notification_large_icon_width"
                        android:scaleType="fitCenter"
                        android:src="@drawable/learning"
                        android:layout_gravity="center"
                        />


                    <TextView
                        android:id="@+id/txtLearning"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/i_name"
                        android:textColor="@color/white"
                        android:textStyle="bold" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:background="@color/yellow"
                    android:orientation="vertical"
                    android:gravity="center"
                    android:layout_margin="1dp"
                    app:layout_columnWeight="1"
                    app:layout_rowWeight="1">


                    <ImageView
                        android:id="@+id/acheivements"
                        android:layout_width="match_parent"
                        android:layout_height="@android:dimen/notification_large_icon_width"
                        android:scaleType="fitCenter"
                        android:src="@drawable/acheivements"

                        />


                    <TextView
                        android:id="@+id/txtAcheivements"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/i_national"
                        android:textColor="@color/white"
                        android:textStyle="bold" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:background="@color/red"
                    android:orientation="vertical"
                    android:gravity="center"
                    android:layout_margin="1dp"
                    app:layout_columnSpan="2"
                    app:layout_rowWeight="1"
                    app:layout_columnWeight="1">

                    <ImageView
                        android:id="@+id/quiz"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:scaleType="fitCenter"
                        android:src="@drawable/quiz" />

                    <TextView
                        android:id="@+id/txtQuiz"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Quiz"
                        android:textColor="@color/white"
                        android:textStyle="bold" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:background="@color/blue2"
                    android:orientation="vertical"
                    android:gravity="center"
                    android:layout_margin="1dp"
                    app:layout_columnWeight="1"
                    app:layout_rowWeight="1">

                    <ImageView
                        android:id="@+id/setting"
                        android:layout_width="match_parent"
                        android:layout_height="@android:dimen/notification_large_icon_width"
                        android:scaleType="fitCenter"
                        android:src="@drawable/setting" />

                    <TextView
                        android:id="@+id/txtSetting"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Setting"
                        android:textColor="@color/white"
                        android:textStyle="bold" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:background="@color/tea"
                    android:orientation="vertical"
                    android:gravity="center"
                    android:layout_margin="1dp"
                    app:layout_columnWeight="1"
                    app:layout_rowWeight="1">

                    <ImageView
                        android:id="@+id/share"
                        android:layout_width="match_parent"
                        android:layout_height="@android:dimen/notification_large_icon_width"
                        android:scaleType="fitCenter"
                        android:src="@drawable/share" />

                    <TextView
                        android:id="@+id/txtshare"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Share"
                        android:textColor="@color/white"
                        android:textStyle="bold" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:background="@color/org"
                    android:orientation="vertical"
                    android:gravity="center"
                    android:layout_margin="1dp"
                    app:layout_columnWeight="1"
                    app:layout_rowWeight="1">

                    <ImageView
                        android:id="@+id/about"
                        android:layout_width="match_parent"
                        android:layout_height="@android:dimen/notification_large_icon_width"
                        android:scaleType="fitCenter"
                        android:src="@drawable/about" />

                    <TextView
                        android:id="@+id/txtAbout"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="About"
                        android:textColor="@color/white"
                        android:textStyle="bold" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:background="@color/green3"
                    android:orientation="vertical"
                    android:gravity="center"
                    android:layout_margin="1dp"
                    app:layout_columnWeight="1"
                    app:layout_rowWeight="1">

                    <ImageView
                        android:id="@+id/moreApps"
                        android:layout_width="match_parent"
                        android:layout_height="@android:dimen/notification_large_icon_width"
                        android:scaleType="fitCenter"
                        android:src="@drawable/moreapps" />

                    <TextView
                        android:id="@+id/txtMoreApps"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="More Apps"
                        android:textColor="@color/white"
                        android:textStyle="bold" />

                </LinearLayout>
            </android.support.v7.widget.GridLayout>

        </LinearLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorAccent"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            />


    </FrameLayout>


    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:menu="@menu/drawer_view"
        app:headerLayout="@layout/nav_header"
        />

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

activity_main.xml

<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"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">


    <include layout="@layout/layout_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/include_layout"
        app:menu="@menu/menu_main_drawer" />

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

include_layout.xml

<LinearLayout android:id="@+id/content_frame"
    android:orientation="vertical"
    android:background="@color/light_black"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        />



    <android.support.v7.widget.GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:columnCount="2"
        app:rowCount="4">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@color/green3"
            android:orientation="vertical"
            android:gravity="center"
            android:layout_margin="1dp"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1">

            <ImageView
                android:id="@+id/learning"
                android:layout_width="match_parent"
                android:layout_height="@android:dimen/notification_large_icon_width"
                android:scaleType="fitCenter"
                android:src="@drawable/learning"
                android:layout_gravity="center"
                />


            <TextView
                android:id="@+id/txtLearning"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/i_name"
                android:textColor="@color/white"
                android:textStyle="bold" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@color/yellow"
            android:orientation="vertical"
            android:gravity="center"
            android:layout_margin="1dp"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1">


            <ImageView
                android:id="@+id/acheivements"
                android:layout_width="match_parent"
                android:layout_height="@android:dimen/notification_large_icon_width"
                android:scaleType="fitCenter"
                android:src="@drawable/acheivements"

                />


            <TextView
                android:id="@+id/txtAcheivements"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/i_national"
                android:textColor="@color/white"
                android:textStyle="bold" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@color/red"
            android:orientation="vertical"
            android:gravity="center"
            android:layout_margin="1dp"
            app:layout_columnSpan="2"
            app:layout_rowWeight="1"
            app:layout_columnWeight="1">

            <ImageView
                android:id="@+id/quiz"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="fitCenter"
                android:src="@drawable/quiz" />

            <TextView
                android:id="@+id/txtQuiz"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Quiz"
                android:textColor="@color/white"
                android:textStyle="bold" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@color/blue2"
            android:orientation="vertical"
            android:gravity="center"
            android:layout_margin="1dp"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1">

            <ImageView
                android:id="@+id/setting"
                android:layout_width="match_parent"
                android:layout_height="@android:dimen/notification_large_icon_width"
                android:scaleType="fitCenter"
                android:src="@drawable/setting" />

            <TextView
                android:id="@+id/txtSetting"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Setting"
                android:textColor="@color/white"
                android:textStyle="bold" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@color/tea"
            android:orientation="vertical"
            android:gravity="center"
            android:layout_margin="1dp"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1">

            <ImageView
                android:id="@+id/share"
                android:layout_width="match_parent"
                android:layout_height="@android:dimen/notification_large_icon_width"
                android:scaleType="fitCenter"
                android:src="@drawable/share" />

            <TextView
                android:id="@+id/txtshare"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Share"
                android:textColor="@color/white"
                android:textStyle="bold" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@color/org"
            android:orientation="vertical"
            android:gravity="center"
            android:layout_margin="1dp"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1">

            <ImageView
                android:id="@+id/about"
                android:layout_width="match_parent"
                android:layout_height="@android:dimen/notification_large_icon_width"
                android:scaleType="fitCenter"
                android:src="@drawable/about" />

            <TextView
                android:id="@+id/txtAbout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="About"
                android:textColor="@color/white"
                android:textStyle="bold" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@color/green3"
            android:orientation="vertical"
            android:gravity="center"
            android:layout_margin="1dp"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1">

            <ImageView
                android:id="@+id/moreApps"
                android:layout_width="match_parent"
                android:layout_height="@android:dimen/notification_large_icon_width"
                android:scaleType="fitCenter"
                android:src="@drawable/moreapps" />

            <TextView
                android:id="@+id/txtMoreApps"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="More Apps"
                android:textColor="@color/white"
                android:textStyle="bold" />

        </LinearLayout>
    </android.support.v7.widget.GridLayout>




</LinearLayout>

主要布局:

<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"
android:background="@color/colorBackground"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="@dimen/size300"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:itemBackground="@drawable/drawer_item_background_selector"
    app:itemTextAppearance="?android:attr/textAppearanceSmall"
    app:itemTextColor="@android:color/black"
    app:menu="@menu/activity_main_drawer">

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

app_bar_main布局:

<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.appsdevelopment.stylus.aci.allor_shathi.activity.MainActivity">

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

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:titleTextAppearance="@style/Toolbar.TitleText" />

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

<FrameLayout
    android:id="@+id/frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="@dimen/size_minus45"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"></FrameLayout>
</android.support.design.widget.CoordinatorLayout>