Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot Resolve @style/Theme.Sherlock

I'm trying to make use of Actionbar Sherlock 4, targeting sdk 15 and min sdk 8. After following the directions provided on the Usage website and the great videos posted here: http://www.youtube.com/watch?v=avcp6eD_X2k

I'm still encountering a problem. When I try to add android:theme="@style/Theme.Sherlock" to my manifest file , I get the error:

No resource found that matches the given name (at 'theme' with value '@style/Theme.Sherlock').

I have included the actionbar Sherlock library project into my project, and the import statements are there and not coming up with any errors and I've

extends SherlockActivity implements ActionBar.TabListener

just like in the Demo code and documentation Yet still, eclipse gives me this error. Any ideas out there?

like image 310
Ten_Ten_Steve Avatar asked Apr 27 '12 14:04

Ten_Ten_Steve


3 Answers

The pitfall I encountered was this: The reference to the ActionBarSherlock project needs to be in the Android->Libraries section of the project properties, while I had been adding it to the Build Path->Libraries.

like image 104
domsom Avatar answered Sep 19 '22 00:09

domsom


I encountered a strange anomaly that might help!

Have built android project that uses ABS, running it on Gingerbread works fine, in ICS it crashes, the crash under ICS occurs due to this, check your AndroidManifest.xml (have trimmed out bits for brevity...

<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" android:theme="@style/Theme.Sherlock">

It was the android:theme part that caused the crash under ICS, it worked fine under Gingerbread and older versions!. Solution was to remove it completely! Then from your Activity, do this:

@Override
public void onCreate(Bundle savedInstanceState) {
   if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){
        this.setTheme(com.actionbarsherlock.R.style.Theme_Sherlock);
   }
   super.onCreate(savedInstanceState);
   ... // MORE CODE ....
}

This fixed up the crash under ICS, the theme style is not liked by ICS, but it works fine for both versions less than 2.3 and 4.0 upwards.. weird error but that I discovered by fluke!

Remember to apply the theme before calling the base class's own onCreate!

like image 41
t0mm13b Avatar answered Sep 20 '22 00:09

t0mm13b


My standard procedure for including a library project on Eclipse goes like this:

  • Import library project
  • Right click on library project Properties -> Android -> Set Project Build Target (insure library and primary project are the same)
  • Right click on library project Android Tools -> Fix Project Properties
  • Select the library project then Project -> Clean...
  • Select primary project then Project -> Clean...

That should fix whatever ails you.

like image 40
dbyoung Avatar answered Sep 21 '22 00:09

dbyoung