2016-04-28 75 views
0

对不起我的英文不好。工具栏出错

我有以下的“activity_main.xml”文件,问题是工具栏不出现,有人告诉我如何让她看起来?

<android.support.v4.widget.DrawerLayout 
android:id="@+id/drawer_layout" 
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="match_parent" 
> 

<RelativeLayout 
android:id="@+id/anchor_point" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/holo_blue_light" 
    /> 

</RelativeLayout> 

<android.support.design.widget.NavigationView 
android:id="@+id/navigation" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:layout_gravity="start" 
app:elevation="4dp" 
app:headerLayout="@layout/drawer_header" 
app:menu="@menu/menu_main"/> 
</android.support.v4.widget.DrawerLayout> 

本等“activity_main.xml中”工具栏会出现,但缺乏抽屉式导航

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res /android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<android.support.v7.widget.Toolbar 
android:id="@+id/toolbar" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@android:color/holo_blue_light" 
> 
</android.support.v7.widget.Toolbar> 

<RelativeLayout 
    android:layout_below="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/container"> 
</RelativeLayout> 

</RelativeLayout> 
+0

尝试加入这一行中navigationview您activity_main xml'android:layout_below =“@ + id/toolbar”'..让我进一步了解.. –

回答

1

尝试这种方式,将工作

<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="match_parent" 
    android:fitsSystemWindows="true" 
    android:orientation="vertical"> 

    <android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/abc_action_bar_default_height_material" 
    android:background="?attr/colorPrimary" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/> 

    <android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <!-- Real content goes here --> 
    <FrameLayout 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

    <!-- The navigation drawer --> 
    <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/drawer"/> 

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