我有一个非常奇怪的问题.我在我的项目中使用ActionbarSherlock.在很少的设备上我得到一个:
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.felitec.dow/de.felitec.dow.ui.LoginActivity}: 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:1815)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
at android.app.ActivityThread.access$500(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
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:976)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(ActionBarSherlockCompat.java:902)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:836)
at com.actionbarsherlock.app.SherlockActivity.setContentView(SherlockActivity.java:229)
at de.felitec.dow.ui.LoginActivity.onCreate(LoginActivity.java:36)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
... 11 more
我的LoginActivity如下所示:
public class LoginActivity extends SherlockActivity implements AuthCallback<OAuthConsumer> {
private ProgressDialog progDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
}
...
而我的清单:
<application
android:label="@string/app_name"
android:icon="@drawable/ic_app_launcher"
android:name=".MainApplication"
android:theme="@style/MainAppTheme">
<activity
android:name=".ui.SplashActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.Sherlock.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".ui.LoginActivity"
android:windowSoftInputMode="adjustPan|stateHidden"
android:screenOrientation="portrait"/>
...
最后我的style.xml:
<style name="MainAppTheme" parent="@style/Theme.Sherlock.Light.DarkActionBar">
<item name="homeAsUpIndicator">@drawable/back_indicator</item>
...
请注意,SplashActivity工作得很好.当它启动LoginActivity的意图时它会崩溃,我真的不明白为什么.
提前致谢
最佳答案 用这个更新你的Manifiest文件.
android:theme="@style/Theme.Sherlock"