Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ActionBar Compatibility

I was going through this sample package which Google has provided with it's sdk. I tried changing the api level to 7 and observed that there were many unresolved errors in the project.

I'm listing a few here:

  1. ICE_CREAM_SANDWICH cannot be resolved or is not a field (ActionBarActivity.java)
  2. R cannot be resolved to a variable (This is probably due to the fact my xml also contains errors)
  3. SHOW_AS_ACTION_IF_ROOM cannot be resolved or is not a field (ActionBarHelperBase.java)
  4. The method setActionView(View) is undefined for the type MenuItem (ActionBarHelperHoneycomb.java)
  5. The method getActionBar() is undefined for the type Activity (ActionBarHelperICS.java)
  6. The import android.view.ActionProvider cannot be resolved (SimpleMenuItem.java)
  7. in res/values-v13/styles.xml - error: Error retrieving parent for item: No resource found that matches the given name 'android:style/ TextAppearance.Holo.Widget.ActionBar.Title'.
  8. error: Error: No resource found that matches the given name: attr 'android:actionBarStyle'. (in res/values-v11/styles.xml)

Any idea how to get rid of these errors? Basically I'm targeting android devices 2.x and later. Does using actionbarsherlock is another alternative? I read here on some post that action bar compatibility package works on 2.x android devices as well.

like image 409
Ankit Garg Avatar asked Mar 15 '12 13:03

Ankit Garg


1 Answers

Right click on your project in the Package Manager, then highlight the Android node in the Properties dialog that opens. You will see a list of Project Build Targets. Select the API level 14, Android 4.0 build target. This will get rid of the error. Unfortunately, that also means it won't show up on your emulated devices that are using Android 2.3.3. You'll have to create a new one in the AVD that supports 4.0.

like image 196
jdbertron Avatar answered Oct 02 '22 16:10

jdbertron