How to remove the "API level required" error?

I get this error in Eclipse: calling requires API level 14 (current min - 8): android.app.ActionBar # setHomeButtonEnabled

This is the code:

if(android.os.Build.VERSION.SDK_INT>=14) { getActionBar().setHomeButtonEnabled(false); } 

In the manifest:

 <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="14" /> 

How to remove this error?

+48
android eclipse
Sep 27 '12 at 23:07
source share
2 answers

Add the line @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) above the method signature, where Build.VERSION_CODES.ICE_CREAM_SANDWICH is evaluated to 14, the API version code for Ice Cream Sandwich.

Same:

 @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public void yourMethod() { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { getActionBar().setHomeButtonEnabled(false); } } 
+93
Sep 27 '12 at 23:10
source share

Note: the accepted answer is out of date.

In Android Studio 3.0 Beta 7 you no longer need the @TargetApi annotation.
It seems that checking the pile is now smarter.

So this is enough:

 public void yourMethod() { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { getActionBar().setHomeButtonEnabled(false); } } 
+2
10 Oct '17 at 16:40
source share



All Articles