Mr.AndroidShin / Dev Tools

Debugging log · Theming

"You need to use a Theme.AppCompat theme with this activity"

The app compiled fine and then crashed the instant the activity appeared, with a message insisting I use a Theme.AppCompat theme. I hadn't touched theming — I'd just added an activity, or swapped a theme to something that looked nicer. The crash is the framework refusing to draw an AppCompat screen with a theme that doesn't give it what it needs.

The short version: an AppCompatActivity (and Material components) require the activity's theme to descend from Theme.AppCompat or Theme.MaterialComponents/Theme.Material3. Point the activity — or the whole app — at such a theme and the crash goes away.

The error

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

Why it happens

AppCompat and Material components rely on a set of theme attributes — color accents, action-bar styles, widget styling — that only exist in AppCompat/Material themes. If your activity is an AppCompatActivity but its theme is a plain platform theme like android:Theme or Theme.Material (the non-AppCompat one), those attributes are missing, and the first thing the activity does when it inflates is check for them and bail. So the usual triggers are: setting an activity's theme to a non-AppCompat one, forgetting to set a theme at all, or using a third-party library activity that expects AppCompat.

The fix — give the activity an AppCompat theme

In res/values/themes.xml, make sure your app theme descends from an AppCompat/Material parent:

<style name="Theme.MyApp" parent="Theme.Material3.DayNight.NoActionBar">
    <!-- your color and style overrides -->
</style>

Then apply it in the manifest — on the whole app, or on the specific activity that's crashing:

<application
    android:theme="@style/Theme.MyApp">

    <activity
        android:name=".SomeActivity"
        android:theme="@style/Theme.MyApp" />
</application>

Theme.Material3.*, Theme.MaterialComponents.* and Theme.AppCompat.* all satisfy the requirement; a bare android:Theme.* does not.

The usual causes, concretely

If you specifically don't want an action bar, use the .NoActionBar variant of an AppCompat/Material theme rather than dropping to a plain platform theme. You keep the AppCompat attributes the activity needs and simply lose the bar.

How to confirm

Theme and activity names above are examples — use your project's own.