9

現在,我剛剛在Android Studio中啓動了一個項目,並在模板中預先配置了NavigationBar。顯然,它將導航抽屜放在操作欄後面。您發現許多問題需要在操作欄上方放置導航抽屜,我希望在操作欄下方開始。這是我目前有:Actionbar下方的導航抽屜

current situation

最終期望的情況:

desired situation

我發現this解決辦法,但我覺得應該有一個更簡單的方法。

+0

抽屜式導航不應該是動作條/工具欄下面,則是針對設計引導線 – tyczj 2014-12-03 21:49:43

+0

是真的? https://developer.android.com/design/patterns/navigation-drawer.html – 2014-12-03 21:51:13

+0

這些是舊的設計指南,這是更新後的http://www.google.com/design/spec/patterns/navigation -drawer.html – tyczj 2014-12-03 21:52:40

回答

15

將此屬性應用於根視圖組android:layout_marginTop="?android:attr/actionBarSize"。希望這可以幫助。

+0

它說:無法解析符號'actionBarSize' – 2014-12-03 22:15:08

+0

你確定嗎?請再看一次我的答案。 – Biu 2014-12-03 22:17:47

+0

現在幾乎!它似乎並沒有把通知欄放在這個邊界之上。 – 2014-12-03 22:21:10

7

試試這個 MainActivity佈局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools"> 
    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/app_bar" 
     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> 
    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="?attr/actionBarSize" 
     android:fitsSystemWindows="true"> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:paddingBottom="@dimen/activity_vertical_margin" 
      android:paddingLeft="@dimen/activity_horizontal_margin" 
      android:paddingRight="@dimen/activity_horizontal_margin" 
      android:paddingTop="@dimen/activity_vertical_margin" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" 
      tools:showIn="@layout/app_bar_main"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Put your content View here!" /> 
     </RelativeLayout> 
     <android.support.design.widget.NavigationView 
      android:id="@+id/nav_view" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      app:headerLayout="@layout/nav_header_main" 
      app:menu="@menu/activity_main_drawer" /> 
    </android.support.v4.widget.DrawerLayout> 
</RelativeLayout> 
+0

您好我正在使用上面的代碼,其工作在SDK 23中很漂亮,當相同的代碼在SDK 19上執行ActionbarTitle不顯示。 ....這是鏈接:http://stackoverflow.com/questions/39957481/android-navigation-drawer-ui-different-displayed-in-below-sdk-22?noredirect=1#comment67194862_39957481 – 2016-10-10 13:19:52

+0

爲什麼不你只是使用layout_below?也許我錯過了一個觀點? – zgulser 2016-11-07 21:29:41