简体   繁体   中英

How to solve: IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity

My app is failing to run in the emulator. The error cited is java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

I've read a number of similar questions, including: .IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity

ActionBarCompat: java.lang.IllegalStateException: You need to use a Theme.AppCompat

But none of these have worked.

The code in the res>values>styles.xml file is:

<resources>

    <style name = "AppBaseTheme" parent = "TextAppearance.AppCompat">
        <item name = "android:colorPrimary">@android:color/holo_blue_bright</item>
        <item name = "android:colorPrimaryDark">@android:color/holo_blue_dark</item>
        <item name = "android:colorAccent">@android:color/holo_red_dark</item>


    </style>



</resources>

The code in the src>main>AndroidManifest.xml file is:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.hbpm1">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppBaseTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

I'd be very grateful if anyone could help:)

Application theme can not be <style name = "AppBaseTheme" parent = "TextAppearance.AppCompat"> , because TextAppearance theme can't be used for Application theme at all. So, use any Theme.AppCompat as the default theme for your application. For this, I can give an example:

<style name = "AppBaseTheme" parent = "Theme.AppCompat">

or

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 

etc.

Hope it will work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM