2016-12-02 95 views
-2

我使用下一个代码在我的应用程序中显示抽屉布局。我需要在标题栏下显示抽屉。但总是把它冠以标题。 我不知道我在哪里做我的错误。以下抽屉标题app

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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/top" 
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.v4.widget.DrawerLayout 
    android:layout_below="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/drawer_layout"> 
    <FrameLayout 
     android:id="@+id/content_frame" 
     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:layout_marginTop="56dp" 
     android:layout_below="@+id/drawer_layout" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header_main" 
     app:menu="@menu/activity_main_drawer" /> 
</android.support.v4.widget.DrawerLayout> 

</RelativeLayout> 

和应用条码是在这里:

<?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="ro.ghiduldrumetului.calauza.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.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="16dp" 
    app:srcCompat="@android:drawable/ic_dialog_email" /> 

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

看到http://stackoverflow.com/questions/ 26985270 /导航 - 抽屉 - 低于工具栏 – cuoka

+0

你有工具栏实施 – Lucifer

+0

测试该解决方案具有相同的结果。 RelativeLayout不帮助我。 –

回答

1

解决

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 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/drawerLayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".MainActivity"> 

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

<android.support.design.widget.NavigationView 
    android:id="@+id/navigation" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    app:menu="@menu/navigation_menu" 
    app:headerLayout="@layout/navigation_header"> 
</android.support.design.widget.NavigationView> 

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

请接受我的答案,如果它有帮助 – Lucifer

0

你可以试试这个

<android.support.v4.widget.DrawerLayout 
android:layout_below="@+id/toolbar" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:id="@+id/drawer_layout"> 
    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/background_color"/> 
<ListView 
    android:id="@+id/drawer" 
    android:layout_width="260dp" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/toolbar" 
    android:layout_marginTop="56dp" 
    android:layout_gravity="start"> 
</ListView> 
+0

如果我尝试<包括 layout =“@ layout/app_bar_main” android:layout_width =“match_parent” android:layout_height =“在我的应用程序崩溃的Framelayout中match_parent“/>。 –

+0

什么是应用程序栏主要? – Lucifer

+0

可以粘贴屏幕截图或其他东西 – Lucifer