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

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

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

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

app:themereplace为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" ,它解决了这个问题。

检查你的布局。

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

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

点击这里查看更多信息。