READ UPDATE 2 BELOW FOR ANSWER
I am trying to use ActionBarSherlock in my application. I checked the 4.0.0 release from the github repo project , built it in Netbeans, and then copied the library-4.0.0.jar file to my lib project directory (I don't use Eclipse).
This is just skeletal activity right now, and it runs very well in ICS, but when I run it on Gingerbread, I get the following exception, complaining that I do not have the Theme.Sherlock application theme (or similar):
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.arashpayan.prayerbook/com.arashpayan.prayerbook.PrayerBook}: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) at android.app.ActivityThread.access$1500(ActivityThread.java:117) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3683) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative. at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(ActionBarSherlockCompat.java:987) at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(ActionBarSherlockCompat.java:899) at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:852) at com.actionbarsherlock.ActionBarSherlock.setContentView(ActionBarSherlock.java:655) at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:316) at com.arashpayan.prayerbook.PrayerBook.onCreate(PrayerBook.java:44) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) ... 11 more
The line he's complaining about (PrayerBook: 44) is a call to setContentView . An application consists of just one action with the onCreate() method, which I call setTheme() from above:
public void onCreate(Bundle savedInstanceState) { setTheme(com.actionbarsherlock.R.style.Theme_Sherlock); super.onCreate(savedInstanceState); TextView rootTextView = new TextView(this); rootTextView.setText("Hello, world!"); setContentView(rootTextView); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.Tab tab = getSupportActionBar().newTab(); tab.setText("Prayers"); getSupportActionBar().addTab(tab); tab = getSupportActionBar().newTab(); tab.setText("Recents"); getSupportActionBar().addTab(tab); tab = getSupportActionBar().newTab(); tab.setText("Bookmarks"); getSupportActionBar().addTab(tab); }
I have to set the theme incorrectly, but I just don’t see how to do it. Can anyone help?
UPDATE Below, CommonsWare noted that the theme can be installed in AndroidManifest.xml. I tried like this:
<application android:label="@string/app_name" android:icon="@drawable/icon" android:theme="@style/Theme.Sherlock"> <activity android:name="PrayerBook" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden|screenLayout|uiMode|mcc|mnc|locale|navigation|fontScale|screenSize"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="LanguagesActivity" /> </application>
but Ant throws an error when trying to create an application:
/Users/arash/coding/prayerbook/AndroidManifest.xml:7: error: Error: No resource found that matches the given name (at 'theme' with value '@style/Theme.Sherlock').
UPDATE 2 With CommonsWare in his subsequent comments, I was able to get it working. I needed to add ActionBarSherlock depending on the project. For this
1) I removed library-4.0.0.jar and android-support-4.0.jar from my lib project.
2) Then go to the library folder inside the root of the ActionBarSherlock directory extracted from github. Enter android update project , so the build.xml and proguard.cfg file will be created for the library.
3) Finally, cd go back to the main directory of the project and add ABS as a library dependency using android update project --path . --library ../ActionBarSherlock/library android update project --path . --library ../ActionBarSherlock/library The path to --library in the command will differ depending on where you checked the repo. ActionBarSherlock and my application project directory were sisters directories.