SherlockActionBar无法在Android 2.3.6上工作(Force Close)

时间:2013-04-01 20:22:08

标签: android android-actionbar actionbarsherlock

但是,在Android 4.0.3上运行正常。 Sherlock不应该为2.xx版本提供ActionBar吗?

我在清单文件中添加了android:theme="@style/Sherlock.__Theme.Light"

我没有在应用程序上运行任何东西:

public class MainActivity extends SherlockActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

}

我也试过extends SherlockFragmentActivity 它还强制关闭2.3.6。但是,4.0.3它起作用了。 任何专家都可以告诉我问题在哪里?

编辑:

04-01 23:24:29.210: E/AndroidRuntime(18249): FATAL EXCEPTION: main
04-01 23:24:29.210: E/AndroidRuntime(18249): java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.lau.autointernetconnector/edu.lau.autointernetconnector.MainActivity}: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
04-01 23:24:29.210: E/AndroidRuntime(18249):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at android.os.Looper.loop(Looper.java:130)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at android.app.ActivityThread.main(ActivityThread.java:3691)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at java.lang.reflect.Method.invokeNative(Native Method)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at java.lang.reflect.Method.invoke(Method.java:507)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at dalvik.system.NativeStart.main(Native Method)
04-01 23:24:29.210: E/AndroidRuntime(18249): Caused by: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
04-01 23:24:29.210: E/AndroidRuntime(18249):    at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(ActionBarSherlockCompat.java:1003)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(ActionBarSherlockCompat.java:915)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:849)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at com.actionbarsherlock.app.SherlockActivity.setContentView(SherlockActivity.java:229)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at edu.lau.autointernetconnector.MainActivity.onCreate(MainActivity.java:12)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-01 23:24:29.210: E/AndroidRuntime(18249):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
04-01 23:24:29.210: E/AndroidRuntime(18249):    ... 11 more

2 个答案:

答案 0 :(得分:1)

虽然你自己回答了你的问题(根据ChristopheCVB给出的评论),我仍然想补充一些内容。

  

但是,在Android 4.0.3上运行正常。不是Sherlock的假设   为2.xx版本提供ActionBar?

ActionBarSherlock仅为Honeycomb下的版本提供ActionBar。您在HC +上看到的ActionBar都是本机实现。

@style/Sherlock.__Theme.Light在HC +上不会失败,因为它们已经设置了所有必需的样式。

答案 1 :(得分:0)

我解决了我的问题......我不敢相信,直到我在这里发布它才能解决它。

我把它放在清单中:android:theme="@style/Theme.Sherlock.Light"而不是android:theme="@style/Sherlock.__Theme.Light"并且它有效:)