Home » Android » Android exception: You need to use a Theme.AppCompat theme with this activity

Android exception: You need to use a Theme.AppCompat theme with this activity

Posted by: admin June 15, 2020 Leave a comment

Questions:

In order to use the support action bar, my activity has to extend ActionBarActivity, and when I do that and start the activity, the application crashes with:

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

In my styles.xml I have

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

And in my AndroidManifest.xml for the offending activity I have

<activity android:name="com.example.test3.SettingsActivity"
          android:theme="@style/AppBaseTheme" />
How to&Answers:

You have to check for other folders, that contain styles files as well, that could possibly override your styles.

Answer:

Write this line in your manifest file.

 android:theme="@style/Theme.AppCompat.Light.NoActionBar"

Sample:

   <activity
        android:name="com.vmoksha.BaseActivity"
        android:label="@string/app_name" 
        android:theme="@style/Theme.AppCompat.Light.NoActionBar"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

And Add this code in your styles.xml inside resource tag

      <style name="Theme.AppCompat.Light.NoActionBar" parent="@style/Theme.AppCompat.Light"> 
        <item name="android:windowNoTitle">true</item>
     </style>

Cheers!

Answer:

Tsung Wu said:

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

Then set the theme in your AndroidManifest.xml:

<application
   android:debuggable="true"
   android:name=".activity.MyApplication"
   android:allowBackup="true"
   android:icon="@drawable/ic_launcher"
   android:label="@string/app_name"
   android:theme="@style/Theme.Event.Home">