我有一个扩展AppCompatActivity的主要活动,当App启动时,立即执行AsyncTask并显示一个对话窗口 忙碌的指标。在应用程序启动时运行时崩溃,我收到以下logcat错误。
我还提到了一些帖子,我尝试了一个建议的解决方案,比如添加以下行
<item name="windowActionBar">false</item>
到styles.xml,但它没有解决问题
styles.xml
<resources>
<!-- Base application 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>
对话框的布局
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/act_main_tv_phase_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="task in progress"
android:textAppearance="?android:attr/textAppearanceLarge" />
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/act_main_tv_phase_name"
android:layout_centerHorizontal="true"
android:minWidth="56dp">
<ProgressBar
android:layout_width="32dp"
android:layout_height="32dp"
android:id="@+id/act_main_pb_busy_indicator"/>
</FrameLayout>
logcat的:
FATAL EXCEPTION: main
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: Process: com.example.com.vpager_00, PID: 20764
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.com.vpager_00/com.example.com.ecoassistant_01.ActMain}: java.lang.IllegalArgumentException: AppCompat does not support the current theme features: { windowActionBar: false, windowActionBarOverlay: false, android:windowIsFloating: false, windowActionModeOverlay: false, windowNoTitle: false }
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2689)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2754)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.app.ActivityThread.access$900(ActivityThread.java:177)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.os.Looper.loop(Looper.java:145)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5938)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: Caused by: java.lang.IllegalArgumentException: AppCompat does not support the current theme features: { windowActionBar: false, windowActionBarOverlay: false, android:windowIsFloating: false, windowActionModeOverlay: false, windowNoTitle: false }
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:422)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:279)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:253)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at com.example.com.ecoassistant_01.ActMain.initViews(ActMain.java:456)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at com.example.com.ecoassistant_01.ActMain.onCreate(ActMain.java:519)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6288)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2642)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2754)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.app.ActivityThread.access$900(ActivityThread.java:177)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.os.Looper.loop(Looper.java:145)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5938)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
02-15 10:05:50.429 20764-20764/com.example.com.vpager_00 E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
02-15 10:06:26.039 20764-20764/com.example.com.vpager_00 I/Process: Sending signal. PID: 20764 SIG: 9
答案 0 :(得分:0)
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowContentOverlay">@null</item>
<item name="actionBarStyle">@style/Widget.AppTheme.ActionBar</item>
</style>
<style name="Widget.AppTheme.ActionBar" parent="Widget.AppCompat.ActionBar.Solid">
<!-- action bar background -->
<item name="background">@color/actionBar</item>
</style>
第一种风格是你的app风格,第二种是app-compat。
答案 1 :(得分:0)
要解决您的问题,您有两种选择:
第一种方法是使用Theme.AppCompat.NoActionBar作为父主题。这可能是正确的。
如果您不能这样做(可能需要支持操作栏而没有操作栏),您应该执行以下操作:
<style name="MyTheme" parent="Theme.AppCompat">
...
</style>
<style name="MyTheme.NoActionBar">
<!-- Both of these are needed -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>