【问题标题】:how i can set Navigation Drawer behind Toolbar我如何在工具栏后面设置导航抽屉
【发布时间】:2017-04-29 14:21:11
【问题描述】:

我正在尝试将 Navigation drawer 设置在 Toolbar 后面,我已经尝试设置 android:layout_marginTop="@dimen/abc_action_bar_default_height_material"NanvigationView 但没有任何改变,我也关注此 Navigation Drawer Below Toolbar 但不起作用

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/top_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<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="false"
    android:theme="@style/NavigationView"
    android:background="#2b2b2b"
    app:itemTextColor="#FFF"
    app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>

App_bar_main.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"
 android:fitsSystemWindows="true"
 tools:context="maa.a4kandhdwallpapers.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" />
  </android.support.design.widget.AppBarLayout>
    <include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>

【问题讨论】:

  • @MikeM。我遵循已批准的答案,但不起作用
  • @MikeM。请检查我尝试设置的更新代码:RelativeLayout ----Toolbar ----DrawerLayout ---ContentView ---DrawerList
  • @MikeM。不幸的是,她没有工作,我尝试将&lt;include layout="@layout/app_bar_main" android:layout_width="match_parent" android:layout_height="match_parent" /&gt; 放在&lt;DrawerLayout&gt; 之前的&lt;NavigationView&gt; 之前,就像你说的那样,但是当我运行它时仍然不起作用,没有任何改变
  • @MikeM。我知道我打扰了你,但我添加了app_bar_main 请帮助我

标签: java android xml navigation-drawer


【解决方案1】:

为 activity_main.xml 尝试下一个代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
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="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:theme="@style/NavigationView"
android:background="#2b2b2b"
app:itemTextColor="#FFF"
app:menu="@menu/activity_main_drawer" 
android:layout_marginTop="@dimen/appbar_height"/>

appbar_height - 您在 dimen.xml 中的值。可以等于?actionBarSize

【讨论】:

    猜你喜欢
    • 2016-03-26
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    • 2016-06-01
    • 1970-01-01
    • 2015-02-26
    • 2015-01-15
    • 1970-01-01
    相关资源
    最近更新 更多