Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting ActionBarSherlock Theme for Android app
    primarykey
    data
    text
    <p><strong>READ UPDATE 2 BELOW FOR THE ANSWER</strong></p> <p>I'm trying to use ActionBarSherlock in my app. I checked out the 4.0.0 release from the <a href="https://github.com/JakeWharton/ActionBarSherlock" rel="noreferrer">project github repo</a>, built it in Netbeans, then copied the library-4.0.0.jar file into my project's lib directory (I'm not using Eclipse).</p> <p>It's just a skeleton activity right now, and it launches just fine in ICS, but when I run it on Gingerbread I get the following exception complaining that I haven't the app theme to Theme.Sherlock (or similar):</p> <pre><code>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 </code></pre> <p>The line it complains about (PrayerBook:44) is the call to <code>setContentView</code>. The app just consists of a single activity with an <code>onCreate()</code> method that I call <code>setTheme()</code> from at the top:</p> <pre><code>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); } </code></pre> <p>I must be setting the theme incorrectly, but I just don't see how. Can anyone help?</p> <p><b>UPDATE</b> Below, CommonsWare noted that the theme can be set in the AndroidManifest.xml. I've tried that like so:</p> <pre><code>&lt;application android:label="@string/app_name" android:icon="@drawable/icon" android:theme="@style/Theme.Sherlock"&gt; &lt;activity android:name="PrayerBook" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden|screenLayout|uiMode|mcc|mnc|locale|navigation|fontScale|screenSize"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name="LanguagesActivity" /&gt; &lt;/application&gt; </code></pre> <p>but Ant gives me an error when it tries to build the app:</p> <pre><code>/Users/arash/coding/prayerbook/AndroidManifest.xml:7: error: Error: No resource found that matches the given name (at 'theme' with value '@style/Theme.Sherlock'). </code></pre> <p><strong>UPDATE 2</strong> With CommonsWare's help in his follow up comments, I was able to get it working. I needed to add ActionBarSherlock as a project dependency. To do so,</p> <p>1) I removed <code>library-4.0.0.jar</code> and <code>android-support-4.0.jar</code> from my project's <code>lib</code> directory.</p> <p>2) Next, navigate into the <code>library</code> folder inside the root of the ActionBarSherlock directory checked out from github. Type <code>android update project</code> so a <code>build.xml</code> and <code>proguard.cfg</code> file will be created for the library.</p> <p>3) Finally, <code>cd</code> back into the main project directory and add ABS as a library dependency with <code>android update project --path . --library ../ActionBarSherlock/library</code> The path to the <code>--library</code> in the command will vary according to where you checked out the repo. ActionBarSherlock and my app's project directory were sibling directories.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload