我已尽力为Android导航抽屉重现UI设计。 我已经设计了导航标题,看起来像UI设计中的内容。 当我运行应用程序时,标题(nav_header_home.xml中的布局)在模拟器中不可见。
导航图的nav_header_home.xml:
<?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>
预期菜单布局的屏幕截图
android模拟器中的布局截图
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>
带有DrawerLayout的action_home.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"
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>
答案 0 :(得分:0)
在@MikeM。的帮助下,我能够以允许我查看导航标题的方式调整布局设置。
他的贡献可以在这里直接阅读 - Home Navigation header of NavigationDrawer not showing in simulator
答案 1 :(得分:0)
将 fitsSystemWindows
和 DrawerLayout
上的 NavigationView
属性设置为 false,如 Mike. M.