2015-11-03 128 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"