Setting ActionBarSherlock Theme for Android app

后端 未结 7 1290
深忆病人
深忆病人 2020-12-01 10:04

READ UPDATE 2 BELOW FOR THE ANSWER

I\'m trying to use ActionBarSherlock in my app. I checked out the 4.0.0 release from the project github repo, bui

相关标签:
7条回答
  • 2020-12-01 10:40

    For me this was caused by not using the @style/ prefix. I.e. I had

    <style name="AppTheme" parent="Theme.Sherlock.Light" />
    

    instead of

    <style name="AppTheme" parent="@style/Theme.Sherlock.Light" />
    

    Which is kind of weird because I swear the default template value is something like:

    <style name="AppTheme" parent="android:Theme.Holo.Light" />
    
    0 讨论(0)
  • 2020-12-01 10:41

    This was happening to me in IntelliJ IDEA. I solved this issue by going to File > Project Structure > Project Settings > Facets > Select actionbarsherlock module in 2nd column > Check the "Library module" checkbox > Apply and OK > Save and Rebuild.

    UPDATE After further review, my original response may be too specific, and will probably only work in certain cases. This error means that the dependencies have not been properly setup. In IntelliJ IDEA, follow these steps to properly setup actionbarsherlock as a module dependency:

    1. Download and extract the actionbarsherlock library from the zip (Note: You only need the “actionbarsherlock” folder)
    2. Copy and paste it alongside your Android project
    3. Open your project in IntelliJ
    4. File > Project Structure > Project Settings > Modules > Add (green ‘+’ above second column) > Import Module > Select actionbarsherlock directory in file browser dialog > OK > Create module from existing sources > Next
    5. Uncheck the “test” folder so it is not added to the project and click “Next”
    6. Under the Libraries tab, android-support-v4 should be checked, click “Next”
    7. Under the Modules tab, actionbarsherlock should be checked, click “Next”
    8. If it asks you to Overwrite actionbarsherlock.iml, choose “Overwrite” and then "Finish" (You should be returned to the Modules section of the Project Structure dialog)
    9. Select the actionbarsherlock module from the second colum and under the Dependencies tab in the third column, check “Export” next to the android-support-v4 library
    10. Almost there!
    11. Now select your project module from the second column, and under the Dependencies tab, click the Add button (green ‘+’ on the far right side of the dialog)
    12. Select Module Dependency and choose actionbarsherlock from the dialog that pops up and press “OK”
    13. Now click “Apply” or “OK” to accept the changes

    That should do the trick.

    0 讨论(0)
  • 2020-12-01 10:49

    Usually, you set your theme in the manifest, as shown in the Android developer documentation (and linked to from the ActionBarSherlock theming page).

    If you want to use ActionBarSherlock everywhere within your app, this works:

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.Sherlock">
    
    0 讨论(0)
  • 2020-12-01 10:52

    If you wanna use custom style, I made a template for custom ActionBarSherlock style. Theme is defined in /values/styles.xml file. It is extended from Theme.Sherlock.Light theme. There are many parameters, you can set: icon, logo, divider, title, shadow overlay, action menu buttons, popup menu, action mode background, dropdown list navigation, tab style, display options etc. Almost everything, what you need, to create your custom action bar theme. I use this template in my apps, because it helps me to style action bar very quickly.

    You can find this template on my GitHub. It is very easy to use. Just copy values and drawable directiories into your project and set android:theme parameter in application element in AndroidManifest.xml:

    <application
        ...
        android:theme="@style/Theme.Example">
    

    Drawables in my template were generated via Android Action Bar Style Generator. I use different naming convention for resources. This simple script renames all resources generated with Android Action Bar Style Generator to my own convention, used in the template.

    0 讨论(0)
  • 2020-12-01 10:58

    Had the same problem. The app crashed altough the theme was set in the manifest. Setting the theme programmatically solved the problem:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.AppTheme);
        super.onCreate(savedInstanceState);
    
    0 讨论(0)
  • 2020-12-01 11:01
    <!--Provides resources-->
    <dependency>
       <groupId>com.actionbarsherlock</groupId>
       <artifactId>library</artifactId>
       <version>4.1.0</version>
       <type>apklib</type>
    </dependency>
    <!-Provides import links-->
    <dependency>
       <groupId>com.actionbarsherlock</groupId>
       <artifactId>library</artifactId>
       <version>4.1.0</version>
       <type>jar</type>
       <scope>provided</scope>
     </dependency>
    

    The hint is to use type "apklib", that's mean that maven will be using all sources (resources too). Other dependecy to jar file (scope "provided") is used to achieve link to sherlock classes during coding.

    0 讨论(0)
提交回复
热议问题