找到你要的答案

Q:Getting AppCompat does not support the current theme features exception after upgrading to version AppCompat v22.1.0 issue

Q:让appcompat不升级版发行后appcompat v22.1.0支持当前主题功能异常

Previously i was using AppCompat with version 21.1.2 in my project for the purpose of material design toggle with toolbar. But after upgrading to AppCompat v22.1.0, my app has started working weird. I even tried some of the solutions like as follows

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

Also applying parent theme as

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

But none of the above solutions was not helpful for me. So kindly please help me by your tips and suggestions to overcome my issue which i am currently facing. I am also posting my styles.xml and logcat error for your reference. Any kind of help would be helpful for me. Thanks in advance.

styles.xml

 <style name="MainActivityTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="colorPrimary">@color/white</item>
        <item name="colorPrimaryDark">#F2F2F2</item>
        <item name="android:windowNoTitle">true</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
        <item name="colorControlActivated">@color/yellow</item>
    </style>

Logcat Error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sample.app/com.sample.app.activities.MainActivity}: java.lang.IllegalArgumentException: AppCompat does not support the current theme features
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
            at android.app.ActivityThread.access$900(ActivityThread.java:175)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5602)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
            at dalvik.system.NativeStart.main(Native Method)
     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 com.sample.app.activities.MainActivity.onCreate(MainActivity.java:24)
            at android.app.Activity.performCreate(Activity.java:5451)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
            at android.app.ActivityThread.access$900(ActivityThread.java:175)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5602)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
            at dalvik.system.NativeStart.main(Native Method)

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

以前我是用appcompat版本21.1.2在我的项目中的材料设计切换工具栏的目的。但升级后appcompat v22.1.0,我的应用程序已经开始工作的怪异。我甚至尝试了一些解决方案,如下所示

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

也应用家长主题为

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

但上述解决方案对我没有任何帮助。所以请帮助我的提示和建议,以克服我的问题,我目前面临的。我也把我的styles.xml logcat的错误供你参考。任何一种帮助都会对我有帮助。先谢谢了。

styles.xml

 <style name="MainActivityTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="colorPrimary">@color/white</item>
        <item name="colorPrimaryDark">#F2F2F2</item>
        <item name="android:windowNoTitle">true</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
        <item name="colorControlActivated">@color/yellow</item>
    </style>

logcat误差:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sample.app/com.sample.app.activities.MainActivity}: java.lang.IllegalArgumentException: AppCompat does not support the current theme features
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
            at android.app.ActivityThread.access$900(ActivityThread.java:175)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5602)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
            at dalvik.system.NativeStart.main(Native Method)
     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 com.sample.app.activities.MainActivity.onCreate(MainActivity.java:24)
            at android.app.Activity.performCreate(Activity.java:5451)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
            at android.app.ActivityThread.access$900(ActivityThread.java:175)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5602)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
            at dalvik.system.NativeStart.main(Native Method)

对java.lang.illegalargumentexception可能重复:appcompat不支持当前的主题特征

answer1: 回答1:

Thank you all for your replies. I solved my issue on my own by removing the line

<item name="android:windowNoTitle">true</item>

The error occurred because of adding windowNoTitle two times as follows

<item name="android:windowNoTitle">true</item>
<item name="windowNoTitle">true</item>

谢谢你们的回复。我去掉了这条线,独自解决了我的问题

<item name="android:windowNoTitle">true</item>

错误发生,因为添加windownotitle两次如下

<item name="android:windowNoTitle">true</item>
<item name="windowNoTitle">true</item>
answer2: 回答2:

Remove .NoActionBar from your MainActivityTheme

<style name="MainActivityTheme" parent="Theme.AppCompat">
        // ................................................
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
</style>

删除从您的mainactivitytheme NoActionBar。

<style name="MainActivityTheme" parent="Theme.AppCompat">
        // ................................................
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
</style>
answer3: 回答3:

Remove

.NoActionBar

from your style, because you already use from a windowNoTitle=false and windowActionBar=false in your Theme.

删除

.NoActionBar

从你的风格,因为你已经从windownotitle =虚假和windowactionbar =假你的主题。

answer4: 回答4:

maybe this help some people

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

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

in addition i use android studio and gradle shot for you is

'com.android.support:appcompat-v7:22.2.0'

fortunately the error goes away.

也许这能帮助一些人

在我的情况,我没有使用noactionbar主题。我只是删除Android前缀从这个项目。

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

另外我用Android Studio和摇篮射你

'com.android.support:appcompat-v7:22.2.0'

幸运的是错误消失了。

answer5: 回答5:

just Use this in your style.xml 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);
}
}

就是用这个在你无需编辑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>

不要在活动文件中添加任何内容,请留下

  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);
}
}
answer6: 回答6:

in my case i have this code ==>

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
            <item name="android:windowNoTitle">true</item>
            <item name="windowActionBar">false</item>
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
</style>

it works when i delete

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

hope this may also help !!!

in my case i have this code ==>

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
            <item name="android:windowNoTitle">true</item>
            <item name="windowActionBar">false</item>
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
</style>

当我删除时

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

希望这也可以帮助!!!

android  android-theme  material-design  android-styles  appcompat-v7-r22.1