在我正在使用的应用程序中使用ActionBar Sherlock
. 我得到的错误似乎很奇怪,因为我对应用程序中的其他 2 个活动使用相同的主题。
显现:
<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 的设备上收到此错误。请帮忙。