Toolbar toggle(burger) button does not work on Android Pre Lollipop

Asked

Viewed 297 times

0

I created a NavigationDrawer same as the image

NavigationDrawer

It works perfectly on Android 5.0 or higher, equal to image. But when I run the application on Android less than 5.0, the button inserir a descrição da imagem aqui does not work and when I open the Drawer menu by sliding it, Toolbar turns dark, with the same shadow that covers the main content of Activity. How can I make Android pre Lollipop menu work the same way?

This is my xml

<?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:orientation="vertical"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

<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:theme="@style/AppTheme.AppBarOverlay"/>

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

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

    <!-- Conteudo da Activity -->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="?attr/actionBarSize"
        android:id="@+id/homeContent">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageView"
            android:layout_marginTop="65dp"
            android:src="@drawable/logo"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="24dp"
            android:layout_marginRight="24dp"
            android:minWidth="250dp"
            android:minHeight="200dp"
            android:contentDescription="@string/logo" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lbltxtHome"
            android:id="@+id/txtInfoHome"
            android:layout_below="@+id/imageView"
            android:layout_centerHorizontal="true"
            android:gravity="center_horizontal" />

    </RelativeLayout>

    <!-- Navigation View -->
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        app:itemIconTint="@color/navDrawerIconColor"
        android:background="@color/navDrawerBackground"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:itemTextColor="@color/navDrawerTextColor"
        app:itemBackground="@drawable/drawer_item"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        android:layout_marginTop="?attr/actionBarSize"
        app:headerLayout="@layout/drawer_base_header"
        app:menu="@menu/drawer_base_menu" />

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

And that’s my Toolbar at the Activity mine

 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Botão Hamburger
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

1 answer

1


Usually the syncState is called in the onPostCreate and make sure you are using the setDrawerIndicatorEnabled

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    toggle.setDrawerIndicatorEnabled(true);
    toggle.syncState();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.