2016-08-30 4 views
1

Я хочу, чтобы заголовок моего навигационного ящика находился ниже строки состояния. При поиске решений каждый результат заключается в том, как разместить его в строке состояния. Я, конечно, попытался «отменить» эти решения, чтобы разместить заголовок ниже. Но это не сработало, и я проверяю его на Samsung Galaxy S7 API 23Как разместить заголовок ящиков навигации под панелью состояния?

Прямо сейчас это выглядит следующим образом:

Это мой макет, содержащий DrawerLayout, NavigationView:

<?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" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#00ffff" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 


    <include 
    android:id="@+id/toolbar_drawer_layout" 
    layout="@layout/navdrawer_toolbar" 
    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:background="@color/arion_darkgray" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/navdrawer_header" 
    app:itemBackground="@drawable/nav_drawer_selector" 
    app:itemIconTint="#fff" 
    app:itemTextColor="#fff" 
    app:menu="@menu/navdrawer_menu" 
    app:theme="@style/custom_navDrawer_style" /> 

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

панель инструментов расположение:

<?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=".MyHorseActivity"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/myhorse_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="@color/arion_darkblue"> 

     <RelativeLayout 
      android:id="@+id/myhorse_toolbar_innerlayout" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@android:color/transparent"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:paddingRight="70dp" 
       android:text="My Horse" 
       android:textColor="#fff" 
       android:textSize="24sp" /> 

      <ImageView 
       android:backgroundTint="#ff0000" 
       android:layout_width="15dp" 
       android:layout_height="15dp" 
       android:layout_alignParentRight="true" 
       android:layout_centerInParent="true" 
       android:layout_marginRight="10dp" 
       android:background="@drawable/circle_shape" /> 
     </RelativeLayout> 

    </android.support.v7.widget.Toolbar> 

    <include 
     layout="@layout/divider_lightblue" 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:layout_alignParentBottom="true"> 

    </include> 


</android.support.design.widget.AppBarLayout> 

<include 
    android:id="@+id/activity" 
    layout="@layout/myhorse_activity_" /> 

Многое из этого автоматически сгенерированных с помощью Android Studio после того как я создал свой NavigationDrawer класс от мастера

ответ

1

Вы не кладете xml полностью, так что я не знаю, что случилось с вашим xml, но если вы хотите, чтобы ваш navigation drawer ниже action bar затем положить ваши drawerlayout ниже вашего toolbar следующего

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <!--Start of the Toolbar and its items --> 
    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" /> 

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

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"></LinearLayout> 

     <!--Used for displaying Navigation Drawer slide--> 
     <LinearLayout 
      android:id="@+id/navigation_drawer" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:orientation="vertical"> 

      <FrameLayout 
       android:id="@+id/navigation_container" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 

     </LinearLayout> 

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

Согласно отредактированному вопросу drawerlayout XML будет как

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <include 
     android:id="@+id/toolbar_drawer_layout" 
     layout="@layout/navdrawer_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <android.support.v4.widget.DrawerLayout 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/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#00ffff" 
     android:fitsSystemWindows="true" 
     tools:openDrawer="start"> 

     <include 
      android:id="@+id/activity" 
      layout="@layout/myhorse_activity_" /> 

     <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:background="@color/arion_darkgray" 
      android:fitsSystemWindows="true" 
      app:headerLayout="@layout/navdrawer_header" 
      app:itemBackground="@drawable/nav_drawer_selector" 
      app:itemIconTint="#fff" 
      app:itemTextColor="#fff" 
      app:menu="@menu/navdrawer_menu" 
      app:theme="@style/custom_navDrawer_style" /> 

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

и панель инструментов макет будет как

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=".MyHorseActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/myhorse_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@color/arion_darkblue"> 

      <RelativeLayout 
       android:id="@+id/myhorse_toolbar_innerlayout" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="@android:color/transparent"> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:paddingRight="70dp" 
        android:text="My Horse" 
        android:textColor="#fff" 
        android:textSize="24sp" /> 

       <ImageView 
        android:layout_width="15dp" 
        android:layout_height="15dp" 
        android:layout_alignParentRight="true" 
        android:layout_centerInParent="true" 
        android:layout_marginRight="10dp" 
        android:background="@drawable/circle_shape" 
        android:backgroundTint="#ff0000" /> 
      </RelativeLayout> 

     </android.support.v7.widget.Toolbar> 

     <include 
      layout="@layout/divider_lightblue" 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:layout_alignParentBottom="true" /> 
    </android.support.design.widget.AppBarLayout> 
</android.support.design.widget.CoordinatorLayout> 
+1

Я согласен с indramurari. с отсутствием взгляда на весь код xml не может точно определить точку прерывания. как всегда пытаться использовать Linear Layout, как указано indramurari – Umanda

+0

@Umanda Это была синтаксическая ошибка, теперь вы можете увидеть весь код – Muddz

+0

@Muddz проверить мой обновленный ответ – Nikhil

0

Я использовал файл XML ниже, чтобы достичь того, что вы просили. Но таким образом ящик открывается ниже как «строки состояния», так и «панели инструментов»

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:orientation="vertical" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity"> 

<include xmlns:android="http://schemas.android.com/apk/res/android" layout="@layout/toolbar" /> 

<android.support.v4.widget.DrawerLayout 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawerLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" 
    android:elevation="5dp"> 

    <FrameLayout 
     android:id = "@+id/frameLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 

     </FrameLayout> 

    <ListView 
     android:background="#ffffff" 
     android:id = "@+id/drawerList" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="left" 
     android:elevation="5dp"></ListView> 

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

</LinearLayout> 
+0

Посмотрите еще раз. Я только что отредактировал со всем соответствующим кодом – Muddz

+0

. Я верю, что indramurari ответил на ваш вопрос. Вам просто нужно использовать линейный макет в качестве родительского тега. и используйте в нем панель инструментов и планшета! – mrfaisal007

+0

Не работает. Мой навигационный экран не отображается, когда я нажимаю кнопку меню. – Muddz

Смежные вопросы