¿Cómo puedo hacer que DrawerLayout se muestre debajo de la barra de herramientas?
¿Cómo hacer que el diseño del cajón esté por debajo de la barra de herramientas / barra de herramientas? Estoy usando v7: 21 app compat library con la nueva vista ToolBar.
Los ejemplos que veo parecen
- Nuevo ícono oficial para Android Navigation Drawer
- ¿Cómo eliminar fragmento el fragmento reemplazado en la transición de fragmentos?
- Cajón de navegación onNavigationDrawerItemSelected llamado antes de MainActivity onCreate?
- ¿Barra de herramientas Android para API 19? (Para la API 21 funciona bien)
- ActionBarDrawerToggle Ningún constructor adecuado Drawable
<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 entonces la barra de herramientas estará oculta por el cajón, lo que hace que un icono de hamburguesa animada (como v7.ActionBarDrawerToggle) sea inútil ya que no será visible debajo del cajón, pero sí quiero usar la nueva vista ToolBar para apoyar mejor el tema Material.
Entonces, ¿cómo lograrlo? ¿Es posible tener DrawerLayout como una vista no de nivel superior?
- El efecto de sombra superpuesto permanece en NavigationView del cajón de navegación
- Borde de desplazamiento de Android Navigation Drawer
- Androide. ¿Cómo puedo deslizar NavigationDrawer de la biblioteca de pruebas Espresso?
- Desenfocar el fondo del cajón de navegación
- Barra de navegación translúcida Lollipop (fitsSystemWindows = "true")
- Android lollipop toolbar conmutador entre abrir / cerrar el cajón y el botón Atrás
- Android: ¿Es mejor crear un nuevo fragmento cada vez que se hace clic en un elemento del cajón de navegación o cargar fragmentos creados anteriormente?
- InflateException en la llamada al método inflater.inflate ()
<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>
No creo que pueda cuando se utiliza la toolbar
personalizada
Pero un trabajo alrededor sería fijar un top_margin
al cajón. (Lo mismo en Google Play Store!)
<!-- drawer view --> <LinearLayout android:layout_marginTop="?attr/actionBarSize" ...
Si encontraste una solución mejor, dímelo también;)
Cambie su estilo de diseño de cajones como en el siguiente
RelativeLayout ----Toolbar ----DrawerLayout ---ContentView ---DrawerList
Mi solución: generar plantilla con Android Studio 2.1.2, plantilla de cajón:
Solo necesitas tres cambios: establece el margen superior en la vista NavigationView
y elimina la barra de estado del overloap en style.xml
<item name="android:windowDrawsSystemBarBackgrounds">false</item> android:fitsSystemWindows="false"
Layout main.xml set margen superior 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 que esto funcione, y finalmente se muestra correctamente. Aquí está la disposición 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 de mover los widgets de diseño alrededor, si uno está debajo de la etiqueta raíz equivocada, obtendrá un
"No
layout_gravity_left
"
excepción.
- ¿Cómo eliminar el error "Llamada requiere nivel de API"?
- ArrayAdapter en android para crear listview simple