升级到 AppCompat v22.1.0 现在得到 IllegalArgumentException: AppCompat 不支持当前的主题功能 [英] Upgraded to AppCompat v22.1.0 and now getting IllegalArgumentException: AppCompat does not support the current theme features

查看:27
本文介绍了升级到 AppCompat v22.1.0 现在得到 IllegalArgumentException: AppCompat 不支持当前的主题功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚升级了我的应用程序以使用新发布的 v22.1.0 AppCompat,现在当我打开我的应用程序时出现以下异常.

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)

我该如何解决?

推荐答案

AppCompat 现在对主题窗口标志的期望更加严格,与您从框架中获得的内容更加匹配.

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

这背后的主要原因是为了支持 AppCompatDialogs在此版本中添加.他们大量使用了 windowNoTitle 标志,而 AppCompat 之前并没有特别注意这一点.

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:

简单的方法是使用 Theme.AppCompat.NoActionBar 作为您的父主题.这将始终做正确的事情.

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.

这篇关于升级到 AppCompat v22.1.0 现在得到 IllegalArgumentException: AppCompat 不支持当前的主题功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆