1

我有一个扩展 AppCompatActivity 的主要活动,当应用程序启动时,会立即执行 AsyncTask 并显示一个带有繁忙指示器的对话框窗口。在应用程序启动时运行时崩溃,我收到以下 logcat 错误。

我还参考了一些帖子,并尝试了其中一种建议的解决方案,例如添加以下行

<item name="windowActionBar">false</item> 

到styles.xml,但它没有解决问题

样式.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>

日志猫

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
4

2 回答 2

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-compat。

于 2016-02-15T09:39:29.640 回答
0

要解决您的问题,您有两种选择:

第一种方法是只使用 Theme.AppCompat.NoActionBar 作为您的父主题。这可能会做正确的事情。

如果你做不到(可能你需要支持action bar和没有action bar),你应该这样做:

<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>
于 2016-02-15T10:00:41.183 回答