在日志中看到消息:"app:theme is deprecated"?

Seeing message in logs: "app:theme is deprecated"?

自从升级到最新的 appcompat 库后,我在我的日志中看到了一条来自 ViewUtils 的消息。

app:theme is now deprecated. Please move to using android:theme instead.

我正在使用 parent="Theme.AppCompat.Light.NoActionBar" 作为我的父主题。

检查您的布局。

您正在使用 Toolbar,其中您定义了 app:theme.

现在支持 22.1 app:theme 已弃用。你应该使用 android:theme

查看 here 了解更多信息。

app:theme 替换为 android:theme,但您可能会遇到不使用 app:theme 的情况。检查您的布局,尤其是工具栏布局。就我而言,我的布局文件中没有 app:theme 。然后看看我的情况:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:styled="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar_actionbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    styled:popupTheme="@style/ToolbarDarkPopup"
    styled:theme="@style/ActionBarThemeOverlay" />

我已将此布局更改为:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar_actionbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/ActionBarThemeOverlay" />

现在我没有看到警告。

也在这里看看: https://chris.banes.me/2015/04/22/support-libraries-v22-1-0/

Chris Banes 的精彩解释

我有另一个案例,当我的 Toolbar 在 styles.xml 中设置样式时发生了这种情况。它看起来像这样:

<style name="AppActionBar" parent="Widget.AppCompat.ActionBar">
    <item name="android:background">@color/ng_blue</item>
    <item name="theme">@style/ThemeOverlay.AppActionBar</item>
    <item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
</style>

name="theme" 更改为 name="android:theme" 并解决了问题。

如果您在样式文件中看到如下代码块;

<item name="theme">@style/MyToolbarTheme</item>

替换它。

<item name="android:theme">@style/MyToolbarTheme</item>