[英]java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. titanium
I'm creating a custom theme for my Titanium application using this theme generator .我正在使用这个主题生成器为我的 Titanium 应用程序创建一个自定义主题。 But when I run my application it's crashing and my log says that I need appCompact
even if I set the theme for sdk > sdk 11.但是当我运行我的应用程序时,它崩溃了,我的日志显示我需要appCompact
即使我将主题设置为 sdk > sdk 11。
And my targeting Android version is API 19 and min SDK version is API14, so I wonder why I need appCompact
.我的目标 Android 版本是 API 19,最小 SDK 版本是 API14,所以我想知道为什么我需要appCompact
。
This is what my log says:这是我的日志所说的:
[ERROR] : TiApplication: (main) [512,512] Sending event: exception on thread: main msg:java.lang.RuntimeException: Unable to start activity ComponentInfo{a.s/org.appcelerator.titanium.TiActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.; Titanium 3.4.0,2014/09/25 16:42,b54c467
[ERROR] : TiApplication: java.lang.RuntimeException: Unable to start activity ComponentInfo{a.s/org.appcelerator.titanium.TiActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
[ERROR] : TiApplication: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
[ERROR] : TiApplication: at android.app.ActivityThread.handleLaunchActivity(Activ
[ERROR] : TiApplication: at android.app.ActivityThread.access$800(ActivityThread.java:135)
[ERROR] : TiApplication: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
[ERROR] : TiApplication: at android.os.Handler.dispatchMessage(Handler.java:102)
[ERROR] : TiApplication: at android.os.Looper.loop(Looper.java:136)
[ERROR] : TiApplication: at android.app.ActivityThread.main(ActivityThread.java:5017)
[ERROR] : TiApplication: at java.lang.reflect.Method.invokeNative(Native Method)
[ERROR] : TiApplication: at java.lang.reflect.Method.invoke(Method.java:515)
[ERROR] : TiApplication: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
[ERROR] : TiApplication: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
[ERROR] : TiApplication: at dalvik.system.NativeStart.main(Native Method)
[ERROR] : TiApplication: Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
[ERROR] : TiApplication: at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:108)
[ERROR] : TiApplication: at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
[ERROR] : TiApplication: at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
[ERROR] : TiApplication: at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:516)
[ERROR] : TiApplication: at org.appcelerator.titanium.TiActivity.onCreate(TiActivity.java:18)
[ERROR] : TiApplication: at android.app.Activity.performCreate(Activity.java:5231)
[ERROR] : TiApplication: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
[ERROR] : TiApplication: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
[ERROR] : TiApplication: ... 11 more
ok please try this,好的,请试试这个,
Add this attribute to your activity将此属性添加到您的活动中
android:theme="@style/Theme.AppCompat"
You are using an ActionBarActivity
, which requires an AppCompat theme.您正在使用ActionBarActivity
,它需要 AppCompat 主题。 I'm not sure how you'd do this with Titanium, but you'd either need to switch to an AppCompat theme or use a regular Activity
(which shouldn't be a problem if you're targeting 11 or above).我不确定您将如何使用 Titanium 执行此操作,但是您需要切换到 AppCompat 主题或使用常规Activity
(如果您的目标是 11 或更高版本,这应该不是问题)。
I know it's very only question but you should include parent theme into your style.我知道这是唯一的问题,但您应该将父主题包含在您的风格中。
<!-- Base application theme. Transparent theme -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="Transparent" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
write the code in style-v11 folder在 style-v11 文件夹中编写代码
name="AppBaseTheme" parent="Theme.AppCompat.Light"
and in styles-v14 folder并在styles-v14文件夹中
name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar"
只需将 ActionBarActivity 更改为 Activity 或 FragmentActivity
It's a bit embarrassing to admit how I've encountered this error, but in a hope to save someone an hour or hair pulling - for me it was a stray ">" that I mistakenly copied into my AndroidManifest
:承认我是如何遇到这个错误有点尴尬,但希望能节省某人一个小时或拉头发 - 对我来说这是一个流浪 ">" 我错误地复制到我的AndroidManifest
:
<application
android:name=".MyApplication"
android:allowBackup="true"
android:fullBackupContent="@xml/my_backup_rules">
android:hardwareAccelerated="true"
android:icon="@mipmap/icon_l"
android:label="@string/app_name"
android:requiredForAllUsers="true"
android:supportsRtl="true"
android:theme="@style/MyAppTheme">
Too easy to miss if you have a very large manifest - the compiler doesn't complain.如果您有一个非常大的清单,就很容易错过 - 编译器不会抱怨。
Delete all the styles in the library project.删除库项目中的所有样式。 Specify Style folder only in main project not in library project.仅在主项目中而不是在库项目中指定 Style 文件夹。 It worked for me :)它对我有用:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.