Example project for ActionBar Compat and Menu Drawer tested on API level 7 (Android 2.1)
This is an eclipse ADT project. If you're looking for something similar on Android Studio you can either try importing this project or check out the fragment based navigation example at https://github.com/AndroidExamples/fragment-navigation instead. That project was created in AS and will be extended to have the action bar compat navigation drawer included.
This project was never intended to be a complete app. Instead I wanted to convert the AcitonBar example project from Android towards an ActionBar Compat project.
Visit this link.
Changes required from demo app
I started from the sample menu drawer app from the official Navigation Drawer Documentation. That sample project requires API level 14 though. The following is a quick overview of what I had to change to get this working with everything from API level 11 and up.
- update theme
- add compat libraries
- extend ActionBarActivity
- change imports
- clean up layout drawer
In your manifest update the application tag to include the following compat theme.
Add compat libraries
Support lib libraries
- and android-support-v7-appcompat.jar to libs folder
- replace android-support-v4.jar in libs folder
You'll have to set up the required android support libraries to get this sample working. The project file (eclipse) contains a local reference to my system set up. Fix that first. The jars are included on this project in the libs folder.
Compat Project setup
- add android-support-v7-appcompat as a library project
The compat library project isn't included here. You can find it in your SDK folder. First import that as an Android project (eclipse File menu > import > android > existing android project) from:
Now you can add this android project as a dependency on your project.
Only for existing projects. In your source files replace the imports to match all support packages.
Some open points listed here
- use proper own namespace attr and styles for pre lvl 14, see: http://stackoverflow.com/questions/17261230/navigation-drawer-not-working-on-pre-ics-versions
- fix invalidateOptionsMenu() calls => use support version
- about nav drawer: http://developer.android.com/training/implementing-navigation/nav-drawer.html
- about actionbar compat: http://developer.android.com/guide/topics/ui/actionbar.html
- setting up support lib: http://developer.android.com/tools/support-library/setup.html