339

I've just upgraded my app to use the newly released v22.1.0 AppCompat and I'm now getting the following exception when I open my app.

Caused by: java.lang.IllegalArgumentException: AppCompat does not support the current theme features
        at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:360)
        at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)

How do I fix it?

jose praveen
  • 1,298
  • 2
  • 10
  • 17
Chris Banes
  • 31,763
  • 16
  • 59
  • 50

4 Answers4

515

AppCompat is now more strict on what it expect in theme window flags, more closely matching what you would get from the framework.

The main reason behind this is to support AppCompatDialogs which we were also adding in this release. They make heavy use of the windowNoTitle flag, which AppCompat previously didn't pay much attention to.

So to fix your issue you have two options:

The easy way is to just use Theme.AppCompat.NoActionBar as your parent theme. This will always do the right thing.

If you can't do that though (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>

You should be back on track now.

David Passmore
  • 6,089
  • 4
  • 46
  • 70
Chris Banes
  • 31,763
  • 16
  • 59
  • 50
  • 129
    Better to have this information in appcompat release notes ;) – Veaceslav Gaidarji Apr 22 '15 at 12:20
  • 2
    My theme includes Theme.AppCompat.Light.NoActionBar. I'm trying to use the delegate version in a PreferenceActivity and I still see this exception... =/ – niqueco Apr 22 '15 at 16:33
  • 42
    If anyone finds that after trying both options the exception still persists, make sure that your activity is calling setContentView after super.onCreate, not before. I called it before for other purposes, but I had to change it to avoid the error. – jmart Apr 22 '15 at 17:49
  • 1
    @niqueco The comments of this answer aren't an appropriate place to work this out. You should ask a separate question to get more attention. – Chris Hayes Apr 23 '15 at 06:30
  • 27
    In my case I had to change true which I had defined previously to true to get rid of the exception. – Meanman Apr 23 '15 at 12:29
  • 12
    @ChrisBanes: You worked with Android at Google- maybe you can persuade the team to release more thorough release notes in the future. This way, Android developers can use it to debug errors with Android design features themselves instead of stumbling onto the errors at compile time. –  Apr 23 '15 at 16:13
  • 3
    Note that you probably have to make this change both in the main styles/themes XML file AND in the v21 version. Caught me. – rfay Apr 23 '15 at 19:29
  • Wow.. I was literally going nuts over this change. It would be nice if this was documented somewhere – Shmuel Apr 27 '15 at 16:21
  • 1
    Keep in mind that you can still use the Light-theme by doing this: Theme.AppCompat.Light.NoActionBar – Tommie Apr 29 '15 at 09:44
  • Hi @ChrisHayes if i include `falsetrue` i get `java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to com.android.internal.widget.ActionBarOverlayLayout$LayoutParams` exception. – Shajeel Afzal May 02 '15 at 16:25
  • 2
    Really what's needed is a list of all attributes that you need to remove the "android:" from. I've spent hours now tracking down which attributes are framework ones and which ones need to use appcompat's. – miguel May 15 '15 at 00:55
  • once you finish above ans things keep replacing * compile 'com.android.support:support-v4:22.1.1@aar' compile 'com.android.support:appcompat-v7:22.1.1@aar' * the I'm not surprise with this QA will get +1000 :D – LOG_TAG May 15 '15 at 07:04
  • I'm getting this same error trying to use AppCompatDelegate, and I still get the crash even though I'm using Theme.AppCompat.NoActionBar and I'm honoring the delegate's contract exactly the same as AppCompatActivity. Any help would be appreciated. – M Dapp May 22 '15 at 19:35
  • make sure *android:windowNoTitle* shouldbe replaced by *windowNoTitle* – LOG_TAG Jul 29 '15 at 08:14
  • 1
    Does this require a custom 'name'? I am currently using the standard 'AppTheme' name and this did not work for me. – Coova May 30 '17 at 19:06
  • Did anything new change with the latest updates? Non of the above is working for me – Pierre Jul 23 '17 at 08:05
  • I'm trying the following, but no result: https://stackoverflow.com/questions/45643107/appcompat-does-not-support-the-current-theme – Ruchir Baronia Aug 11 '17 at 23:36
34

Those who're still getting error after all of those fix.

Please inherit from

Theme.AppCompat.Light.NoActionBar

and don't use

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

Then, you won't get any error.

Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80
Adnan
  • 8,468
  • 9
  • 29
  • 45
13

I added

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

but it wasnt enough. Finally, moving super.onCreate before setContentView in Activity - fixed my issue :)

   public void onCreate(Bundle savedInstanceState) {    

        super.onCreate(savedInstanceState);    
        setContentView(R.layout.v2_main_dash);
        ...
Sergey Vakulenko
  • 1,655
  • 18
  • 23
  • Thankfully found your answer of moving setContentView after onCreate, I'm struggled with it for half a day... – Oliv Apr 25 '16 at 13:01
0

Just use this in your style.xml in values-v21 folder no other editing is needed

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

    <!-- theme customizations -->

   <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
 </style>

Don't add anything in to activity file please leave it

public class Main extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
Ribin Haridas
  • 1,630
  • 11
  • 17