I am using a Nexus 7 with the Android 5.0 preview build.
On this page http://developer.android.com/tools/support-library/index.html
I see
Changes for v7 appcompat library: Updated
ActionBarDrawerToggle
, which contains the menu-to-arrow animation
Is this what the Google Play app uses? Am I reading too much into this statement? What do I need to change to get this behavior - I can't find it in the API documentation.
It is very easy.
Your layout with DrawerLayout looks the same as always. You use android.support.v4.widget.DrawerLayout and create drawers and content area:
Main changes are in your java code. In your Activity, where you use drawer layout, you have to extend it for ActionBarActivity from v7. Then you create variables for DrawerLayout and ActionBarDrawerToggle. Your imports should look like this:
and then just connect everything. Remember that new drawer layout does not have icon! You just dont pass it where you normally should be. Code for my activity:
And it should work.
You seem to have a working drawer as I read it, if not, the Documentation on "Creating a Navigation Drawer" is pretty good.
The above quote refers to Create a new ActionBarDrawerToggle with arrow and hamburger menu commit. As a related one:
setDrawerIndicatorEnabled
was added in Add ability to disable drawer indicator in new ArrowDrawer.So make sure
setDrawerIndicatorEnabled
is not called withfalse
and useinstead of
which should be pretty obvious from deprecation warnings anyway:
Probably also need
First, make sure you update to latest SDK. Create new Project in Android Studio, then add appcompat-v7.21.0.+ and appcompat-v4.21.0.+ libraries in your buid.gradle as gradle dependency.
Add primaryColor and primarycolorDark in your color.xml file.
Add drawer open/close string value in your strings.xml file.
Your activity_my.xml layout file looks like this:
Your toolbar.xml layout file looks like this:
Your MyActivity.java looks like this: Here your activity must extends ActionBarActivity and set your toolbar as support actionbar.
Create style.xml file in values-21 folder for android lollipop
Create your style.xml file in values folder for older versions then android lollipop
Your AndroidManifest.xml is looks like this:
For reference only: you can download complete source code from here : click here
Check out here
MainActivity.java:
activity_main.xml:
I've posted a sample app here that uses the new Toolbar class and ActionBarToggle to provide an ActionBar with the Play Store style animating icon:
https://github.com/03lafaye/LollipopDrawerToggle
The no-v7-support branch uses the ActionBarToggle with a framework Activity and Toolbar. The master branch uses the v7 Toolbar and an ActionBarActivity.
The setup for not using an ActionBarActivity looks like this:
Note that you have to disable the window actionbar and title bar in your theme like so:
I imagine the sample code for the latest v7 appcompat library will be released soon enough making this post obsolete.
Chris Renke from Square published an alternate backport of the up icon animation. The code is on GitHub here: https://github.com/ChrisRenke/DrawerArrowDrawable and he wrote a blog about it at http://chrisrenke.com/drawerarrowdrawable.