I was reading Using the Action Bar and it says, “… if you want to use Action Bar APIs, such as to add tabs or modify Action Bar styles, you need to set the android:minSdkVersion to ’11’, so you can access the ActionBar class.” But, in the I/O project, the Manifest has ‘7’ as the minSdkVersion. How are they able to do the themes and tabs? I’m having trouble following what they’re doing.
Thanks
I think the important code to look at is in ActivityHelper and ActivityHelperHoneycomb. Basically they’re setting
android:targetSdkVersion="11"andandroid:minSdkVersion="7", then selectively calling the new ActionBar APIs on Honeycomb (or higher) and their own custom action bar implementation pre-Honeycomb.If you don’t already have action bar code for pre-Honeycomb, there’s a nice project called ActionBarSherlock which allows you to simply use the ActionBar API and have it work on pre-Honeycomb (just change some imports).
NOTE: If you decide to use ActionBarSherlock and you’ve upgraded your environment to use the newly released API level 13r1 or 12r2 code make sure to use version 3.0.3 or higher (more info here).
EDIT: A little more background to better answer your question. Setting
android:targetSdkVersion="11"is enough to give you access to theActionBarclass. Settingandroid:targetSdkVersion="7"allows the app to run on pre-honeycomb devices, but callingActionBarcode from them would result in aNoClassDefFoundError(or maybeNoSuchMethodError?).To avoid that, they’re using
ActivityHelperfor API levels < 11 andActivityHelperHoneycombon API levels >= 11. ActivityHelper#createInstance(Activity) is where they decide which to use.