我最近将我的应用程序升级为材质主题。但是,我在 4.2.2 三星平板电脑上遇到了崩溃。堆栈跟踪(发布在下面)告诉我,我没有使用 Theme.AppCompat 的后代,即使我相信我是。该应用程序似乎在 4.4 和 5.0 上运行良好。
这是三星平板电脑的堆栈跟踪:
02-23 19:21:29.490: E/AndroidRuntime(20724): FATAL EXCEPTION: main
02-23 19:21:29.490: E/AndroidRuntime(20724): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.name/com.app.name.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
02-23 19:21:29.490: E/AndroidRuntime(20724): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245)
02-23 19:21:29.490: E/AndroidRuntime(20724): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
02-23 19:21:29.490: E/AndroidRuntime(20724): at android.app.ActivityThread.access$700(ActivityThread.java:150)
02-23 19:21:29.490: E/AndroidRuntime(20724): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
02-23 19:21:29.490: E/AndroidRuntime(20724): at android.os.Handler.dispatchMessage(Handler.java:99)
02-23 19:21:29.490: E/AndroidRuntime(20724): at android.os.Looper.loop(Looper.java:175)
02-23 19:21:29.490: E/AndroidRuntime(20724): at android.app.ActivityThread.main(ActivityThread.java:5279)
02-23 19:21:29.490: E/AndroidRuntime(20724): at java.lang.reflect.Method.invokeNative(Native Method)
02-23 19:21:29.490: E/AndroidRuntime(20724): at java.lang.reflect.Method.invoke(Method.java:511)
02-23 19:21:29.490: E/AndroidRuntime(20724): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
02-23 19:21:29.490: E/AndroidRuntime(20724): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
02-23 19:21:29.490: E/AndroidRuntime(20724): at dalvik.system.NativeStart.main(Native Method)
02-23 19:21:29.490: E/AndroidRuntime(20724): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
02-23 19:21:29.490: E/AndroidRuntime(20724): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
02-23 19:21:29.490: E/AndroidRuntime(20724): at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
02-23 19:21:29.490: E/AndroidRuntime(20724): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
02-23 19:21:29.490: E/AndroidRuntime(20724): at com.appconstructor.core2.MainActivity.onCreate(MainActivity.java:56)
02-23 19:21:29.490: E/AndroidRuntime(20724): at com.app.name.MainActivity.onCreate(MainActivity.java:12)
02-23 19:21:29.490: E/AndroidRuntime(20724): at android.app.Activity.performCreate(Activity.java:5283)
02-23 19:21:29.490: E/AndroidRuntime(20724): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
02-23 19:21:29.490: E/AndroidRuntime(20724): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
02-23 19:21:29.490: E/AndroidRuntime(20724): ... 11 more
我的应用程序使用库进行活动。清单看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.name"
android:versionCode="501"
android:versionName="5.0.1" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
[... Permissions]
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
[... Other activities]
[... etc]
</application>
</manifest>
/res/values/styles.xml
包含在库中,如下所示:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<!-- enable window content transitions -->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
如您所见,AppTheme 确实扩展了 Theme.AppCompat!
还有一些其他values
文件夹,但似乎都不适用。我有荷兰语翻译的 values-nl,values-v19
然后values-v21
是values-w820dp
不包含styles.xml 的。主应用程序中没有样式。
所以,我显然错过了一些东西。会是什么呢?\
更新 1:由于平板电脑实际上真的很慢,我可以看到活动实际上加载为全息。所以问题是加载了错误的主题。