Android DrawerToggle Animation FragmentPagerAdapter

348 views Asked by At

I used to add a single Fragment to my Activity in onCreate. I've switched to using a ViewPager with a FragmentPagerAdapter. Now the "burger" in the action bar is always an arrow, and doesn't animate when opening the drawer.

How can I have the ActionBarDrawerToggle be a "burger" when the drawer is closed, animate to an arrow when opening, and then animate back to a "burger" when closing, while still keeping the ViewPager?

EDIT: Here's the layout of the Activity (SlidingTabLayout taken from here)

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                    android:id="@+id/drawer"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:background="@color/itp_blue">

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

        <com.itpvoip.dev.orange.widgets.SlidingTabLayout
                android:id="@+id/sliding_tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        <android.support.v4.view.ViewPager
                android:id="@+id/drawer_pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
    </LinearLayout>

    <ListView
            android:id="@+id/drawer_list"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:choiceMode="singleChoice"
            android:paddingTop="8dp"
            android:paddingBottom="8dp"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:background="?colorPrimaryDark">

    </ListView>

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

There are 2 answers

0
Eliezer On BEST ANSWER

The issue was that some of the Fragments were altering the ActionBar's display state. Cleaning that up helped get the animation back.

0
UDI On

Please use the new drawer toggle from V7 support Lib

import android.support.v7.app.ActionBarDrawerToggle; 

The new toggle animation comes with it