当前位置: 动力学知识库 > 问答 > 编程问答 >

android - how to make the Appcompat supports the current theme

问题描述:

I have a main activity that extends AppCompatActivity and when the App starts an AsyncTask is executed immediately and shows a dialog window

with a busy indicator. at run time when the App starts it crashes and i receive the below logcat errors.

i also referred to some posts and i tried one of the suggested solutions like adding the following line

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

to the styles.xml, but it did not solve the problem

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>

layout of the dialog

<?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

网友答案:
 <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>

The first style is your app style and the second is the app-compat.

网友答案:

To fix your issue you have two options:

The first way is to just use Theme.AppCompat.NoActionBar as your parent theme. This may do the right thing.

If you can't do that (maybe you need to support action bar and no action bar), you should do the following:

<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>
分享给朋友:
您可能感兴趣的文章:
随机阅读: