2015-11-03 130 views
0

我想在下面的代码中将导航抽屉放在ActionBar /工具栏的顶部。问题是,我未在xml文件中添加工具栏,并且style.xml文件中的操作栏设置已设置为false。但是仍然会在窗口中自动添加一个操作栏。我不知道是什么导致这个操作栏/工具栏被添加。自动添加工具栏

enter image description here

以下是代码:

NavigationDrawer_Activity.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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    > 

    **<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>**  
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="Layout Here" 
     android:gravity="center"/> 

    <android.support.design.widget.NavigationView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     android:layout_gravity="start" 
     app:headerLayout="@layout/navigation_view_header_layout" 
     app:menu="@menu/navigation_view_list_items"/> 

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

styles.xml

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
    </style> 
    <style name="AppTheme.NoActionBar"> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
    </style> 
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

</resources> 

问题:

  • 如果我不添加此工具栏,是什么导致它出现?
  • 如何将NavigationDrawer放在这个自动添加的工具栏之上?

最佳

回答

0

取出windowActionBar财产和改变你的风格父母这样的:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 

您要添加此工具栏:

<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" /> 

为了删除此不显示一个工具栏?

+0

我完全错过了。问题仍然存在。工具栏现在覆盖整个屏幕。点击导航抽屉列表项不起作用。请参阅编辑的NavigationDrawer_Activity.xml – user2498079

+0

请原谅我,如果我误解了你的问题,但我已经编辑了我的答案。似乎你正在添加一个工具栏,当你不需要的时候,只要删除它? – vguzzi

+0

不,我想删除主题自动添加的那个。我的要求是在手动添加的工具栏上放置幻灯片导航抽屉。但是现在,当我在xml文件中添加工具栏时,它会填充整个显示,并且导航视图中的项目已变得无法点击 – user2498079

0

在清单

变化

android:theme="@style/AppTheme" 

android:theme="@style/Theme.AppCompat.NoActionBar"