在我正在使用ActionBar Sherlock
的应用程序中。我得到的错误似乎很奇怪,因为我在应用程序中为其他两个活动使用相同的主题。
清单:
<activity
android:name=".ABC"
android:label="@string/app_name"
android:theme="@style/transTheme" >
<intent-filter >
<action android:name="com.example.ABC"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".XYZ"
android:label="@string/app_name"
android:theme="@style/transTheme" >
<intent-filter >
<action android:name="com.example.XYZ"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".123"
android:label="@string/app_name"
android:theme="@style/transTheme" >
<intent-filter >
<action android:name="com.example.123"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
样式:
<!-- Transparent Layout Themeing -->
<style name="transTheme" parent="android:style/Theme.Translucent">
<item name ="android:windowNoTitle">true</item>
<item name ="android:windowContentOverlay">@null</item>
<item name ="android:backgroundDimEnabled">true</item>
<item name ="android:background">@android:color/transparent</item>
</style>
与清单文件一样,活动ABC和XYZ可以正常工作。我在活动123中得到了错误。
错误日志:
09-08 10:40:08.446: E/AndroidRuntime(23791): FATAL EXCEPTION: main
09-08 10:40:08.446: E/AndroidRuntime(23791): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vaw.selfhelp/com.vaw.selfhelp.SureSMS}: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
09-08 10:40:08.446: E/AndroidRuntime(23791): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
09-08 10:40:08.446: E/AndroidRuntime(23791): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
09-08 10:40:08.446: E/AndroidRuntime(23791): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-08 10:40:08.446: E/AndroidRuntime(23791): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
09-08 10:40:08.446: E/AndroidRuntime(23791): at android.os.Handler.dispatchMessage(Handler.java:99)
09-08 10:40:08.446: E/AndroidRuntime(23791): at android.os.Looper.loop(Looper.java:130)
09-08 10:40:08.446: E/AndroidRuntime(23791): at android.app.ActivityThread.main(ActivityThread.java:3687)
09-08 10:40:08.446: E/AndroidRuntime(23791): at java.lang.reflect.Method.invokeNative(Native Method)
09-08 10:40:08.446: E/AndroidRuntime(23791): at java.lang.reflect.Method.invoke(Method.java:507)
09-08 10:40:08.446: E/AndroidRuntime(23791): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
09-08 10:40:08.446: E/AndroidRuntime(23791): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
09-08 10:40:08.446: E/AndroidRuntime(23791): at dalvik.system.NativeStart.main(Native Method)
09-08 10:40:08.446: E/AndroidRuntime(23791): Caused by: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
09-08 10:40:08.446: E/AndroidRuntime(23791): at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(ActionBarSherlockCompat.java:1003)
09-08 10:40:08.446: E/AndroidRuntime(23791): at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(ActionBarSherlockCompat.java:915)
09-08 10:40:08.446: E/AndroidRuntime(23791): at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:849)
09-08 10:40:08.446: E/AndroidRuntime(23791): at com.actionbarsherlock.app.SherlockActivity.setContentView(SherlockActivity.java:229)
09-08 10:40:08.446: E/AndroidRuntime(23791): at com.vaw.selfhelp.SureSMS.onCreate(SureSMS.java:29)
09-08 10:40:08.446: E/AndroidRuntime(23791): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-08 10:40:08.446: E/AndroidRuntime(23791): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
09-08 10:40:08.446: E/AndroidRuntime(23791): ... 11 more
SureSMS.java(或123.java)第29行
setContentView(R.layout.123layout);
我确实尝试使用
setTheme(R.style.transTheme)
在java类中摆脱了错误,但这并不是活动的透明度。该应用程序适用于HoneyComb及以上设备。我只是在Android 3.0以下的设备上收到此错误。 请帮忙。
答案 0 :(得分:1)
问题是您没有使用ActionBarSherlock提供的主题。您必须使用Theme.Sherlock or Theme.Sherlock.Light or Theme.Sherlock.Light.DarkActionBar
才能使操作栏正常工作。
选项1:
您可以删除所有特定活动的主题,并将主题添加到应用程序上下文中。
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock" >
选项2:
您可以更改
<activity
android:name=".123"
android:label="@string/app_name"
android:theme="@style/transTheme" >
到
<activity
android:name=".123"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock" >
选项3:
您可以使用
<style name="transTheme" parent="android:style/Theme.Sherlock">
而不是使用
<style name="transTheme" parent="android:style/Theme.Translucent">