引起:java.lang.IllegalStateException:您需要在此活动中使用Theme.AppCompat主题(或后代)

时间:2022-02-14 21:12:40

Hi guys I've got this problem Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.I tried to customise my own theme and then applied it to the whole application in manifest but i get that problem and the app crashes. please help. first is my manifest.xml, second is my customised xml file and the last one is the styles.xml. thanks

大家好我有这个问题引起:java.lang.IllegalStateException:你需要使用一个Theme.AppCompat主题(或后代)与此活动。我试图自定义我自己的主题,然后将其应用于整个应用程序显示,但我得到了这个问题,应用程序崩溃了。请帮忙。首先是我的manifest.xml,第二个是我自定义的xml文件,最后一个是styles.xml。谢谢

enter code here

在此处输入代码

<application
    android:allowBackup="true"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/BashsTheme">


    <activity
        android:name=".HomeActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:label="@string/app_name">


        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".AddItems"
        android:configChanges="keyboardHidden|orientation|screenSize" />

    <activity
        android:name=".ViewList"
        android:configChanges="keyboardHidden|orientation|screenSize" />

</application>

<color name="bashs_color">#3B444B</color>

<style name="BashsTheme" parent="android:Theme.Light">
    <item name="android:windowBackground">@color/bashs_color</item>


</style>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

1 个解决方案

#1


0  

1. Make your AddItems and ViewList classes to extend Activity if your using the theme android:Theme.Light..

1.如果你使用主题android:Theme.Light,使你的AddItems和ViewList类扩展Activity。

OR

2. Let your AddItems and ViewList classes to extend ActionBarActivity and implement the appcompat theme like Theme.AppCompat.Light

2.让你的AddItems和ViewList类扩展ActionBarActivity并实现像Theme.AppCompat.Light这样的appcompat主题

UPDATE :

in this file ...

在这个文件中......

<color name="bashs_color">#3B444B</color>

<style name="BashsTheme" parent="Theme.AppCompat.Light">
    <item name="android:windowBackground">@color/bashs_color</item>


</style>

As ActionBarActivity requires appcompat theme..

由于ActionBarActivity需要appcompat主题..

Thank you.. hope it helps.. :)

谢谢..希望它有帮助.. :)

#1


0  

1. Make your AddItems and ViewList classes to extend Activity if your using the theme android:Theme.Light..

1.如果你使用主题android:Theme.Light,使你的AddItems和ViewList类扩展Activity。

OR

2. Let your AddItems and ViewList classes to extend ActionBarActivity and implement the appcompat theme like Theme.AppCompat.Light

2.让你的AddItems和ViewList类扩展ActionBarActivity并实现像Theme.AppCompat.Light这样的appcompat主题

UPDATE :

in this file ...

在这个文件中......

<color name="bashs_color">#3B444B</color>

<style name="BashsTheme" parent="Theme.AppCompat.Light">
    <item name="android:windowBackground">@color/bashs_color</item>


</style>

As ActionBarActivity requires appcompat theme..

由于ActionBarActivity需要appcompat主题..

Thank you.. hope it helps.. :)

谢谢..希望它有帮助.. :)