androidnavigation-drawerui-design

Home Navigation header of NavigationDrawer not showing in simulator


I have done my best to reproduce a UI design for an android navigation drawer. I have already designed the nav header to look like what is in the UI design. When I run the app, the header (the layout in nav_header_home.xml) is not visible in the simulator.

The nav_header_home.xml for the navigationdrawer:

<?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"
    android:layout_height="wrap_content"
    android:background="@color/clientPrimaryBlue"
    android:gravity="center"
    android:orientation="horizontal"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        app:srcCompat="@drawable/home" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="8dp"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:text="Home"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

</LinearLayout>

activity_home_drawer.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:showIn="navigation_view">

    <item android:title="Movies">
        <menu>
            <item
                android:id="@+id/nav_action"
                android:icon="@drawable/ic_menu_share"
                android:title="Action" />
            <item
                android:id="@+id/nav_adventure"
                android:icon="@drawable/ic_menu_send"
                android:title="Adventure" />
            <item
                android:id="@+id/nav_comedy"
                android:icon="@drawable/ic_menu_send"
                android:title="Comedy" />
            <item
                android:id="@+id/nav_crime"
                android:icon="@drawable/ic_menu_send"
                android:title="Crime" />
            <item
                android:id="@+id/nav_drama"
                android:icon="@drawable/ic_menu_send"
                android:title="Drama" />
            <item
                android:id="@+id/nav_fantasy"
                android:icon="@drawable/ic_menu_send"
                android:title="Fantasy" />
        </menu>
    </item>
    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_actors"
            android:icon="@drawable/ic_menu_camera"
            android:title="Actors" />
        <item
            android:id="@+id/nav_directors"
            android:icon="@drawable/ic_menu_gallery"
            android:title="Directors" />
        <item
            android:id="@+id/nav_producers"
            android:icon="@drawable/ic_menu_slideshow"
            android:title="Producers" />
    </group>

    <item android:title="My Account">
        <menu>
            <item
                android:id="@+id/nav_update_profile"
                android:icon="@drawable/ic_menu_share"
                android:title="Update Profile" />
            <item
                android:id="@+id/nav_reset_password"
                android:icon="@drawable/ic_menu_send"
                android:title="Reset Password" />
            <item
                android:id="@+id/nav_sign_out"
                android:icon="@drawable/ic_menu_send"
                android:title="Sign Out" />
        </menu>
    </item>

</menu>

Screenshot of expected menu layout

enter image description here

Screenshot of layout in android emulator

enter image description here

app_bar_home.xml:

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context="media.client.clientmediaandroid.activity.home.HomeActivity">

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

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

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_dialog_email" />

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

action_home.xml with the DrawerLayout:

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

    <include
        layout="@layout/app_bar_home"
        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="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_home"
        app:menu="@menu/activity_home_drawer" />

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

Solution

  • With help from @MikeM., I was able to adjust my layout settings in a way that allowed me to see the navigation header.

    His contribution can be read directly here - Home Navigation header of NavigationDrawer not showing in simulator