在日志中看到消息:“app:theme已过时”?

49

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

app:theme现在已经被弃用,请改用android:theme。

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


2
警告并不是在抱怨主题本身,而是关于“app”关键字的。您应该开始使用“android”代替“app”。 - Blackbelt
你正在使用工具栏吗? - Blackbelt
是的,我正在使用工具栏。 - spierce7
4
查看包含工具栏的布局,寻找“app:”,将其替换为“android:”。 - Blackbelt
请查看此处的官方信息:https://android-developers.googleblog.com/2015/04/android-support-library-221.html - Bruno Bieri
4个回答

73

app:theme替换为android:theme,但您可能会遇到一种情况,即未使用app:theme。检查您的布局,特别是工具栏布局。在我的情况下,我没有在布局文件中使用app:theme,那么请看看我的情况:

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的解释很好。


“popupTheme”怎么办?我们是否也应该使用“android”而不是“styled”? - BamsBamx
@BamsBamx 不,只要你使用支持库工具栏,就可以继续使用styled:popupTheme、styled:contentInsetStart等样式属性。 这些是由支持库声明的可样式化属性。 - sorianiv
1
但是这个解决方案适用于每个版本的Android,还是有任何版本不接受使用andoid:teme? - Pau Arlandis Martinez
1
@PauArlandisMartinez 这里有更多信息:https://stackoverflow.com/questions/57279615/what-is-the-difference-b-w-apptheme-androidtheme-in-android-programming - riQQ

19

我有另外一个案例,在这种情况下我的工具栏在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",问题就被解决了。


那是我搜索“:theme”时没有找到的地方,因为我没有考虑到这个位置...... - prom85

16

检查你的布局。

你正在使用一个定义了app:themeToolbar

从支持库22.1开始,app:theme已经被弃用。你应该使用android:theme

在这里查看更多信息


1
如果在样式文件中看到以下代码块;
<item name="theme">@style/MyToolbarTheme</item>

替换它。
<item name="android:theme">@style/MyToolbarTheme</item>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接