personalizado ejemplo android navigation-drawer android-support-library toolbar drawerlayout

android - ejemplo - navigation drawer personalizado



¿Cómo hago que DrawerLayout se muestre debajo de la barra de herramientas? (5)

¿Cómo hacer que el diseño del cajón esté debajo de la barra de acciones / barra de herramientas? Estoy usando la biblioteca de compatibilidad de aplicaciones v7: 21 con la nueva vista ToolBar.

Ejemplos que veo parecen

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/my_drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- drawer view --> <LinearLayout android:layout_width="304dp" android:layout_height="match_parent" android:layout_gravity="left|start"> <!-- drawer content --> </LinearLayout> <!-- normal content view --> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!-- The toolbar --> <android.support.v7.widget.Toolbar android:id="@+id/my_awesome_toolbar" android:layout_height="wrap_content" android:layout_width="match_parent" android:minHeight="?attr/actionBarSize" android:background="?attr/colorPrimary" /> <!-- The rest of content view --> </LinearLayout>

Pero la barra de herramientas quedará oculta por el cajón, lo que hace que un icono de hamburguesa animado (como v7.ActionBarDrawerToggle) sea inútil, ya que no será visible debajo del cajón, pero sí quiero usar la nueva barra de herramientas para soportar mejor el tema Material.

Entonces, ¿cómo lograr eso? ¿Es posible tener DrawerLayout como una vista no de nivel superior?


Cambie el estilo de diseño del cajón como se muestra a continuación

RelativeLayout ----Toolbar ----DrawerLayout ---ContentView ---DrawerList


Mi solución: generar plantilla con Android Studio 2.1.2, plantilla de cajón:

Solo necesita tres cambios: establecer el margen superior a la vista NavigationView y eliminar la barra de estado overloap en style.xml

<item name="android:windowDrawsSystemBarBackgrounds">false</item> android:fitsSystemWindows="false"

layout main.xml set margin top obtener tamaño actionbar valor android:layout_marginTop="?attr/actionBarSize"

<?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:fitsSystemWindows="false" tools:openDrawer="start"> <include layout="@layout/app_bar_main" 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:layout_marginTop="?attr/actionBarSize" android:fitsSystemWindows="false" app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" /> </android.support.v4.widget.DrawerLayout>


Tuve problemas para hacer que esto funcione, y finalmente se muestra correctamente. Aquí está el diseño que utilicé:

<LinearLayout...[add your namespaces, etc] android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:fitsSystemWindows="true"> <android.support.v7.widget.Toolbar [your custom toolbar] /> <android.support.v4.widget.DrawerLayout [your drawer layout] /> <LinearLayout> [content here] </LinearLayout> <android.support.design.widget.NavigationView /> </LinearLayout>

Tenga cuidado al mover los widgets de diseño, si uno está debajo de la etiqueta raíz incorrecta, obtendrá un

"no layout_gravity_left "

excepción.


no creo que puedas cuando utilizas una toolbar personalizada

pero una top_margin sería establecer un top_margin en el cajón. (lo mismo en google play store!)

<!-- drawer view --> <LinearLayout android:layout_marginTop="?attr/actionBarSize" ...

si encontraste una mejor solución dímelo también;)


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- The toolbar --> <android.support.v7.widget.Toolbar android:id="@+id/my_awesome_toolbar" android:layout_height="wrap_content" android:layout_width="match_parent" android:minHeight="?attr/actionBarSize" android:background="?attr/colorPrimary" /> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/my_drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- drawer view --> <LinearLayout android:layout_width="304dp" android:layout_height="match_parent" android:layout_gravity="left|start"> <!-- drawer content --> </LinearLayout> <!-- normal content view --> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!-- The rest of content view --> </LinearLayout> </android.support.v4.widget.DrawerLayout> </LinearLayout>