NavigationDrawer的主导航标题未显示在模拟器中 [英] Home Navigation header of NavigationDrawer not showing in simulator

查看:80
本文介绍了NavigationDrawer的主导航标题未显示在模拟器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已尽力为Android导航抽屉重现UI设计. 我已经设计了nav标头,使其看起来像UI设计中的样子. 当我运行应用程序时,标题(nav_header_home.xml中的布局)在模拟器中不可见.

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.

导航抽屉的nav_header_home.xml:

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:

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

android模拟器中布局的屏幕截图

Screenshot of layout in android emulator

app_bar_home.xml:

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和DrawerLayout:

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>

推荐答案

在@MikeM.的帮助下,我能够以允许我看到导航标题的方式调整布局设置.

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

他的贡献可以在这里直接阅读- NavigationDrawer的Home Navigation标头未显示在模拟器

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

这篇关于NavigationDrawer的主导航标题未显示在模拟器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆