java.lang.IllegalArgumentException: AppCompat 不支持当前主题功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29784124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 08:36:45  来源:igfitidea点击:

java.lang.IllegalArgumentException: AppCompat does not support the current theme features

javaandroideclipseandroid-studio

提问by Adam Varhegyi

I tried to migrate a project from Eclipse to Android studio. Finally I am able to run it, but at a certain point I got this exception, and I found nothing in google about this:

我试图将一个项目从 Eclipse 迁移到 Android Studio。最后我能够运行它,但在某个时候我得到了这个异常,我在谷歌中没有发现任何关于这个的信息:

04-22 00:08:15.484    9891-9891/hu.illion.kwindoo E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{hu.illion.kwindoo/hu.illion.kwindoo.activity.MainActivity}: java.lang.IllegalArgumentException: AppCompat does not support the current theme features
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2092)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
    ...    
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)
    at hu.illion.kwindoo.activity.MainActivity.onCreate(MainActivity.java:73)
    at android.app.Activity.performCreate(Activity.java:5047)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
    ...

73. line of MainActivity is:

73. MainActivity 的行是:

setContentView(R.layout.activity_main);

Please advice me if you can.

如果可以,请给我建议。

采纳答案by SteelBytes

alternative to @sbaar's answer,

替代@sbaar的答案,

keep windowActionBarto falseand add windowNoTitleas well and set it to true.

保持windowActionBarfalse并加入windowNoTitle以及和它设置为true

ie

IE

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

回答by sbaar

Remove

消除

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

from your theme, then make sure you are inheriting from a .NoActionBar Theme, then set your toolbar like normal.

从你的主题开始,然后确保你是从 .NoActionBar 主题继承的,然后像往常一样设置你的工具栏。

回答by wilddev

Check if you call setContentView()after super.onCreate(), and not before. This helped in my case.

检查您是否setContentView()在 之后super.onCreate()而不是之前调用。这对我有帮助。

回答by Anggrayudi H

Make sure that your theme is child from Theme.AppCompat.NoActionBar, then in styles.xml:

确保您的主题是 child from Theme.AppCompat.NoActionBar,然后在styles.xml

<style name="MyMaterialTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="windowNoTitle">true</item>
        ...
</style>

Btw, it's a new issue for Support Library 22.1.

顺便说一句,这是支持库 22.1 的一个新问题。

回答by Gail

I had the same problem when I upgraded the library version from 22.0.0 to 22.1.1 and fixed it by dropping back to the previous version: com.android.support:appcompat-v7:22.0.0 and go back to using ActionBarActivity, not AppCompatActivity in my Activity classes as required by the newer version of the compatibility library. I'll try again later.

当我将库版本从 22.0.0 升级到 22.1.1 并通过回退到以前的版本来修复它时,我遇到了同样的问题:com.android.support:appcompat-v7:22.0.0 并返回使用 ActionBarActivity,不是我的 Activity 类中的 AppCompatActivity 是新版本的兼容性库所要求的。我稍后再试。

回答by Ribin Haridas

just Use this in your style.xml no other editing is needed

只需在 style.xml 中使用它,无需其他编辑

 <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);
}

 }

回答by atrivedi

Use this parent in Style.xml parent="Theme.AppCompat.Light.NoActionBar"

在 Style.xml parent="Theme.AppCompat.Light.NoActionBar" 中使用此父级

回答by rewrihitesh

Make sure that

确保

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

are at the top of everything this works for me....good luck

对我来说是最重要的......祝你好运

回答by Setmax

in my case i didnt change to .NoActionBar Theme. i just remove android prefix from this item.

就我而言,我没有更改为 .NoActionBar 主题。我只是从这个项目中删除了 android 前缀。

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

and the error goes away.

错误消失了。

回答by ???? ???????

In Java class change Main extends ActionBarActivityto Main extends Activity. It worked for me.

在 Java 类中更改Main extends ActionBarActivityMain extends Activity. 它对我有用。