【问题标题】:Getting AppCompat does not support the current theme features exception after upgrading to version AppCompat v22.1.0 issue升级到AppCompat v22.1.0版本后获取AppCompat不支持当前主题功能异常问题
【发布时间】:2015-07-12 02:22:23
【问题描述】:

以前我在我的项目中使用 21.1.2 版本的 AppCompat 来使用工具栏进行材料设计切换。但是在升级到 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 does not support the current theme features 可能重复

【问题讨论】:

    标签: android android-theme material-design android-styles android-appcompat


    【解决方案1】:

    也许这对某些人有帮助

    在我的情况下,我没有使用 .NoActionBar 主题。我只是从这个项目中删除了 android 前缀。

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

    另外我使用 android studio 和 gradle shot 给你的是

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

    幸运的是错误消失了。

    【讨论】:

      【解决方案2】:

      就我而言 我有这个代码==>

      <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>
      

      希望这也能有所帮助!!!

      【讨论】:

        【解决方案3】:

        只需在您的 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);
        }
        }
        

        【讨论】:

          【解决方案4】:

          感谢大家的回复。我通过删除该行自行解决了我的问题

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

          错误是因为添加了两次windowNoTitle,如下

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

          【讨论】:

          • 我认为不是两次添加 windowNoTitle 造成的。如果你有 android:windowNoTitle 会导致崩溃,所以你必须使用不带 android 前缀的名称。
          • 我遇到了一个大问题,因为我想实现一个库,但我不知道它为什么会崩溃,而您的回答解决了它。我只需要你的代码的第二行。谢谢男人
          • 欢迎您@Alejandroi。很高兴我的解决方案对您有所帮助。
          • 你拯救了我的一天!谢谢你:)
          【解决方案5】:

          从 MainActivityTheme 中删除 .NoActionBar

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

          【讨论】:

            【解决方案6】:

            删除

            .NoActionBar
            

            根据您的风格,因为您已经在主题中使用了 windowNoTitle=falsewindowActionBar=false

            【讨论】:

              猜你喜欢
              • 2015-06-29
              • 1970-01-01
              • 1970-01-01
              • 2015-08-20
              • 2017-08-07
              • 2018-01-20
              • 1970-01-01
              相关资源
              最近更新 更多