【问题标题】:Why AppCompat does not support the current theme features windowActionBar: false为什么 AppCompat 不支持当前主题功能 windowActionBar: false
【发布时间】:2017-12-08 23:18:04
【问题描述】:

为什么 AppCompat 不支持当前主题功能 { windowActionBar: false, windowActionBarOverlay: false, android:windowIsFloating: false, windowActionModeOverlay: false, windowNoTitle: false

    IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2473)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535)
    at android.app.ActivityThread.access$1100(ActivityThread.java:154)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1396)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5582)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
 Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
    at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:359)
    at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
    at com.github.paolorotolo.appintro.AppIntroBase.onCreate(AppIntroBase.java:79)
    at com.infos.activities.Activity_Splash.onCreate(Activity_Splash.kt:27)
    at android.app.Activity.performCreate(Activity.java:6321)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread

我的主题风格

 <!-- Base application theme. -->
    <style name="MyTheme" parent="MyMaterialTheme.Base">

    </style>

    <style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="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>
        <item name="android:windowBackground">@color/windowBackground</item>
        <item name="colorButtonNormal">@color/colorPrimary</item>
        <item name="colorControlActivated">@color/colorPrimary</item>
    </style>

【问题讨论】:

标签: android android-theme


【解决方案1】:

试试这个,

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="windowActionBar">false</item>
    <item name="windowActionBarOverlay">false</item>
    <item name="windowIsFloating">false</item>
    <item name="windowActionModeOverlay">false</item>
    <item name="windowNoTitle">false</item>
</style>

【讨论】:

    【解决方案2】:

    转到您的 styles.xml 并使用 NoActionBar 更改您的主题父级 像这样

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

    【讨论】:

      【解决方案3】:

      您需要检查两个样式文件 styles.xmlstyles.xml(v21) 以防您的代码中有它。

      两个样式文件都必须有一个基于 Theme.AppCompat 主题的父主题,或者它的子主题。

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

      【讨论】:

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