Setting Up the New ActionBarCompat in Android Studio
Setting up the new ActionBarCompat in Android Studio
Continuing from my previous post, I’m toying around with a couple new projects, and I wanted to use some of the new compatibility libraries that Google’s offering for Android. Unfortunately, the setup is a bit involved, and the instructions are a bit scattered. I figured that it might be worth collecting them in a quick post. My main source of this info was the following DevBytes video:
How to
1
Create a new project in Android Studio. I’ll skip the long explanation here, but if you have trouble with it, check out my previous post, it should get you going.
EDIT: Don’t forget to install the Support Libraries in the Android SDK manager.
2
The Gradle dependencies that we need are the same as was shown in my previous post, but here’s the build.gradle
file for this project, just the same:
Add dependency in build.gradle
3
Adding a theme to the Activity in the manifest is really simple:
4
The theme needs to exist, and the parent must be one of the AppCompat provided themes.
Note: Any custom theme elements need to be defined twice, once for the compatibility version in the default namespace, one for the higher API levels in the android namespace.
5
Go to the Activity, and change it to extend ActionBarActivity
instead of Activity
.
6
Add a custom namespace to the menu.xml
. Menu items need to be added using the support library, using the custom namespace.
And that’s it! You should be all set, be sure to give it a shot on both Froyo or Gingerbread devices as well as ICS and above. Here’s the full repo on github.