升级到v22后,AppCompat不支持当前主题功能

时间:2015-09-27 14:26:30

标签: android android-appcompat

升级到Android的AppCompat 22版后,我收到以下错误。

foo SQL_log bar SIZE = 1024 baz

以下是styles.xml

Caused by: java.lang.IllegalArgumentException: AppCompat does not support the current theme features
        at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:363)
        at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)

我也尝试过建议here的解决方案,但它似乎不起作用。

非常感谢任何帮助!

这是Manifest:

<?xml version="1.0" encoding="utf-8"?>
<resources
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/blah.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/blah.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

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

    <style name="topBarLeftIcon">
        <item name="android:paddingLeft">@dimen/top_bar_left_icon_left_padding_default</item>
        <item name="android:paddingRight">@dimen/top_bar_left_icon_right_padding_default</item>
        <item name="android:paddingTop">@dimen/top_bar_left_icon_top_padding_default</item>
        <item name="android:paddingBottom">@dimen/top_bar_left_icon_bottom_padding_default</item>
    </style>

    <style name="editTextStyle">
        <item name="android:padding">@dimen/edit_text_padding_default</item>
    </style>

    <style name="Divider1">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">1dp</item>
        <item name="android:background">@color/default_divider_color1</item>
    </style>

    <style name="Divider2">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">1dp</item>
        <item name="android:background">@color/default_divider_color2</item>
    </style>

    <style name="Divider3">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">1dp</item>
        <item name="android:background">@color/default_divider_color3</item>
    </style>

    <style name="VerticalDivider2">
        <item name="android:layout_width">1dp</item>
        <item name="android:layout_height">match_parent</item>
        <item name="android:background">@color/default_divider_color2</item>
    </style>


    <style name="CustomActionBar" parent="Theme.AppCompat.Light">
        <item name="android:actionBarStyle"  tools:ignore="NewApi">@style/HomeActionBar</item>
        <item name="android:actionMenuTextColor"  tools:ignore="NewApi">@color/actionBarTitleColor</item>
        <item name="android:homeAsUpIndicator"  tools:ignore="NewApi">@drawable/up_icon</item>

        <item name="actionBarStyle">@style/HomeActionBar</item>
        <item name="actionMenuTextColor">@color/actionBarTitleColor</item>
        <item name="homeAsUpIndicator">@drawable/up_icon</item>

        <item name="windowActionModeOverlay">true</item>
        <item name="colorPrimary">@color/bgBlue1</item>
        <item name="colorPrimaryDark">@color/bgBlue1</item>

    </style>

    <style name="HomeActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">

        <item name="android:background"  tools:ignore="NewApi">@drawable/action_bar_blue</item>
        <item name="background">@drawable/action_bar_blue</item>
        <item name="android:titleTextStyle"  tools:ignore="NewApi">@style/HomeActionBar.Text</item>
        <item name="titleTextStyle">@style/HomeActionBar.Text</item>

    </style>

    <style name="HomeActionBar.Text" parent="TextAppearance.AppCompat">
        <item name="android:textColor">@color/actionBarTitleColor</item>
        <item name="android:textSize">@dimen/action_bar_primary_action_font_size</item>
    </style>

    <style name="WhiteActionBar" parent="Theme.AppCompat.Light">
        <item name="android:actionBarStyle"  tools:ignore="NewApi">@style/WhiteActionBar.Style</item>
        <item name="android:actionMenuTextColor"  tools:ignore="NewApi">@color/signature_action_bar_title_color</item>
        <item name="android:homeAsUpIndicator"  tools:ignore="NewApi">@drawable/back_icon</item>

        <item name="actionBarStyle">@style/WhiteActionBar.Style</item>
        <item name="actionMenuTextColor">@color/signature_action_bar_title_color</item>
        <item name="homeAsUpIndicator">@drawable/back_icon</item>

        <item name="windowActionModeOverlay">true</item>

    </style>

    <style name="WhiteActionBar.Style" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:background"  tools:ignore="NewApi">@color/white</item>
        <item name="background">@color/white</item>
        <item name="android:titleTextStyle"  tools:ignore="NewApi">@style/WhiteActionBar.Style.Text</item>
        <item name="titleTextStyle">@style/WhiteActionBar.Style.Text</item>
    </style>

    <style name="WhiteActionBar.Style.Text" parent="TextAppearance.AppCompat">
        <item name="android:textColor">@color/signature_clear_button_text_color</item>
        <item name="android:textSize">@dimen/action_bar_primary_action_font_size</item>
    </style>

    <style name="BoldDivider">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">1dp</item>
        <item name="android:background">@color/default_heading_color</item>
    </style>

    <style name="BoldDividerInline">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">1dp</item>
        <item name="android:background">@color/default_heading_color</item>
    </style>

    <style name="SemiBoldDivider">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">1dp</item>
        <item name="android:background">@color/semibold_divider_color</item>
    </style>

</resources>

1 个答案:

答案 0 :(得分:0)

AppCompat现在对主题窗口标志的期望更加严格,更接近于从框架中获得的内容。

因此,要解决您的问题,您有两种选择:

简单的方法是使用Theme.AppCompat.NoActionBar作为您的父主题。这将永远是正确的。

如果您不能这样做(可能需要支持操作栏而没有操作栏),您应该执行以下操作:

<style name="CustomActionBar" parent=" Theme.AppCompat.NoActionBar">
        <item name="android:actionBarStyle"  tools:ignore="NewApi">@style/HomeActionBar</item>
        <item name="android:actionMenuTextColor"  tools:ignore="NewApi">@color/actionBarTitleColor</item>
        <item name="android:homeAsUpIndicator"  tools:ignore="NewApi">@drawable/up_icon</item>

        <item name="actionBarStyle">@style/HomeActionBar</item>
        <item name="actionMenuTextColor">@color/actionBarTitleColor</item>
        <item name="homeAsUpIndicator">@drawable/up_icon</item>

        <item name="windowActionModeOverlay">true</item>
        <item name="colorPrimary">@color/bgBlue1</item>
        <item name="colorPrimaryDark">@color/bgBlue1</item>

        <!-- Both of these are needed -->
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

我在CustomActionBar

下添加了这两个属性
<!-- Both of these are needed -->
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>

    ...

让我们使用它进行更新并测试它。