设置ActionBarSherlock的主题为Android应用 [英] Setting ActionBarSherlock Theme for Android app

查看:164
本文介绍了设置ActionBarSherlock的主题为Android应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

,读取,更新2所示的答案

我试图用ActionBarSherlock在我的应用程序。我检查了从项目github上回购的4.0.0版本,它建在Netbeans中,然后复制该库4.0.0。 jar文件到我的项目的lib目录下(我不使用Eclipse)。

I'm trying to use ActionBarSherlock in my app. I checked out the 4.0.0 release from the project github repo, built it in Netbeans, then copied the library-4.0.0.jar file into my project's lib directory (I'm not using Eclipse).

这只是一个骨架活动,现在,它启动只是罚款,ICS,但是当我在姜饼运行它,我得到下面的异常抱怨说我没有应用主题Theme.Sherlock(或类似):

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):

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

它抱怨该行约(祈祷书:44)是调用的setContentView 。该应用程序只包含有一个的onCreate()的方法,我称之为 setTheme()单个活动从顶部

The line it complains about (PrayerBook:44) is the call to setContentView. The app just consists of a single activity with an onCreate() method that I call setTheme() from at the top:

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 must be setting the theme incorrectly, but I just don't see how. Can anyone help?

更新 下面,CommonsWare指出,主题可以在AndroidManifest.xml进行设置。我已经试过了,像这样:

UPDATE Below, CommonsWare noted that the theme can be set in the AndroidManifest.xml. I've tried that like so:

<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 gives me an error when it tries to build the app:

/Users/arash/coding/prayerbook/AndroidManifest.xml:7: error: Error: No resource found that matches the given name (at 'theme' with value '@style/Theme.Sherlock').

更新2 随着CommonsWare在他跟进的评论的帮助下,我能得到它的工作。我需要添加ActionBarSherlock作为项目依赖。要做到这一点,

UPDATE 2 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,

1)我删除库4.0.0.jar Android的支持 - 4.0.jar 从我项目的 LIB 目录。

1) I removed library-4.0.0.jar and android-support-4.0.jar from my project's lib directory.

2)接下来,导航到库ActionBarSherlock目录的根目录里面文件夹从github上签出。键入 Android的更新项目所以的build.xml proguard.cfg 的文件将在库中创建。

2) Next, navigate into the library folder inside the root of the ActionBarSherlock directory checked out from github. Type android update project so a build.xml and proguard.cfg file will be created for the library.

3)最后,光盘返回到主项目目录,并添加ABS作为库依赖与 Android的更新项目--path。 --library ../ ActionBarSherlock /库 的路径 - 在命令库将根据您签了回购协议而有所不同。 ActionBarSherlock和我的应用程序的项目目录中同级目录。

3) Finally, cd back into the main project directory and add ABS as a library dependency with android update project --path . --library ../ActionBarSherlock/library The path to the --library in the command will vary according to where you checked out the repo. ActionBarSherlock and my app's project directory were sibling directories.

推荐答案

通常情况下,你设置你的主题在清单中,如图的the Android开发者文档(从的ActionBarSherlock主题化页)。

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

如果你想你的应用程序中的任何地方使用ActionBarSherlock,这个作品:

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">

这篇关于设置ActionBarSherlock的主题为Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆