【问题标题】:IllegalStateException Window.FEATURE_SUPPORT_ACTION_BAR in Activity活动中的 IllegalStateException Window.FEATURE_SUPPORT_ACTION_BAR
【发布时间】:2017-06-09 17:37:41
【问题描述】:

我正在使用 Android 支持库 25.0.0 并且一切正常,但是如果您安装了我的应用程序并且我升级到最新版本 25.3.1 某些设备崩溃,似乎只在三星、HTC 和一加中。堆栈跟踪是:

Caused by java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
       at android.support.v7.app.AppCompatDelegateImplV9.setSupportActionBar(AppCompatDelegateImplV9.java:207)
       at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:130)

当我使用时会发生这种情况

setSupportActionBar(toolbar);

我从 Theme.AppCompat 扩展,但是我扩展了这个主题并覆盖了这个数据

<style name="MyTheme.NoActionBar" >
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

问题是,在更新之前我没有这个主题的崩溃报告,在我更新之后我的 Crashlytics 上出现了这个崩溃。 谢谢

【问题讨论】:

    标签: android android-studio android-actionbar styles android-support-library


    【解决方案1】:

    尝试将此作为您应用程序的主题,并在需要操作栏的地方使用工具栏,使用setSupportActionBar(toolbar);

     <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
            <item name="colorControlNormal">@color/primary_light</item>
            <item name="android:textColorHint">@color/primary_light</item>
    
        </style>
    

    并删除此自定义主题

    <style name="MyTheme.NoActionBar" >
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
        </style>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多