回答については、以下の更新 2 をお読みください。
アプリで ActionBarSherlock を使用しようとしています。プロジェクト github repoから 4.0.0 リリースをチェックアウトし、Netbeans でビルドしてから、library-4.0.0.jar ファイルをプロジェクトの lib ディレクトリにコピーしました (Eclipse は使用していません)。
これは今のところ単なるスケルトン アクティビティであり、ICS で問題なく起動しますが、Gingerbread で実行すると、次の例外が発生し、Theme.Sherlock (または同様のもの) にアプリのテーマがないことを訴えます。
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
それが文句を言う行 (PrayerBook:44) は への呼び出しsetContentView
です。このアプリは、上部からonCreate()
呼び出すメソッドを含む単一のアクティビティで構成されています。setTheme()
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);
}
テーマを間違って設定しているに違いありませんが、方法がわかりません。誰でも助けることができますか?
更新 以下、CommonsWare は、AndroidManifest.xml でテーマを設定できることを指摘しました。私はそれを次のように試しました:
<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>
しかし、Ant がアプリをビルドしようとするとエラーが表示されます。
/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 を追加する必要がありました。そうするために、
1)プロジェクトのディレクトリからlibrary-4.0.0.jar
andを削除しました。android-support-4.0.jar
lib
2) 次に、library
github からチェックアウトした ActionBarSherlock ディレクトリのルート内のフォルダーに移動します。そのandroid update project
ように入力するbuild.xml
とproguard.cfg
、ライブラリ用のファイルが作成されます。
3) 最後にcd
、メイン プロジェクト ディレクトリに戻り、ABS をライブラリの依存関係として追加します。コマンド内android update project --path . --library ../ActionBarSherlock/library
のパスは--library
、リポジトリをチェックアウトした場所によって異なります。ActionBarSherlock と私のアプリのプロジェクト ディレクトリは兄弟ディレクトリでした。