I want to use the actionbar feature included in SDK 11. However I also want the app to run on earlier devices from SDK 10 (2.3.3). I am willing to give up the actionbar feature for the earlier devices as it is not an important feature. I have done all the reading about reflection, wrapper class and some other techniques. I am now stumped on exactly how to make this work. I am using Eclipse.
If I don't set the target in Eclipse to sdk 11 or greater, then any place I have a reference to actionBar gives a compile error. If I put the target to sdk 11 or greater it compiles but won't show that it can run on earlier devices. I have android:minSdkVersion=10
set all the time.
Can someone give me some insight on how to make the references to actionBar
and yet get it to target a previous sdk level? Thanks in advance.
Yes! You can definitely do this. Try following the pattern outlined below.
In your
AndroidManifest.xml
file declare the following (replacing the platform versions with whatever your app requires):By targeting a platform version of API 11 or higher, you are allowing Eclipse to link (compile) against the native ActionBar classes. Providing an earlier minimum platform version allows your app to be installed (run) on older versions of Android.
Your Activity code should then look something like this:
Where the
CompatibilityManager.java
class simply provides static helper methods for determining the current version of the SDK:You might also consider leveraging the ActionBarSherlock library, which provides a compatible ActionBar API all the way back to Android 2.x:
Have fun!