Reputation: 181
I'm developing an application that should be compatible with APIs from 8 above. For versions of API>=11 I display some text in the ActionBar title, and for API<11 the text is shown in the TitleBar. This is handled by Android automatically.
If the API is 11 or above, I would like to get rid of the ActionBar icon to get some more space for the text. However, Eclipse won't let me call getActionBar()
saying that my minimum API (8) is too low.
How can I bypass that?
Upvotes: 1
Views: 1333
Reputation: 1521
You can check your android version by
if (android.os.Build.VERSION.SDK_INT < 11)
{
//your code
}
But I'd actually advice you to use this android support package by google itself to support features on lower versions. Check it out
Upvotes: 2
Reputation: 82583
You can wrap all your ActionBar calls in:
if (android.os.Build.VERSION.SDK_INT>=android.os.Build.VERSION_CODES.HONEYCOMB) {
// call something for API Level 11+
}
The error you are getting is likely a Lint warning, and you should be able to go into the preference and reduce its level to a warning, so that your code still compiles.
Additionally, you could look into using ActionBarSherlock to get an ActionBar on devices lower than API 11.
Upvotes: 6