【发布时间】:2019-03-10 07:29:04
【问题描述】:
我正在尝试更改 Material Components Theme 的样式属性(如 colorPrimaryVariant、colorOnSecondary 等),但出现以下错误:
Android resource linking failed
Output: C:\...\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3835: error: style attribute 'attr/colorPrimaryVariant (aka com.sample.app:attr/colorPrimaryVariant)' not found.
C:\...\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3836: error: style attribute 'attr/colorOnPrimary (aka com.sample.app:attr/colorOnPrimary)' not found.
C:\...\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3839: error: style attribute 'attr/colorSecondaryVariant (aka com.sample.app:attr/colorSecondaryVariant)' not found.
C:\...\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3840: error: style attribute 'attr/colorOnSecondary (aka com.sample.app:attr/colorOnSecondary)' not found.
error: failed linking references.
这是我的主题的样子:
<resources>
<!-- Light application theme -->
<style name="CBTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="colorPrimary">@color/cbPrimary</item>
<item name="colorPrimaryDark">@color/cbPrimaryDark</item>
<item name="colorPrimaryVariant">@color/cbPrimaryDark</item>
<item name="colorOnPrimary">#FFFFFF</item>
<item name="colorAccent">@color/cbAccent</item>
<item name="colorSecondary">@color/cbAccent</item>
<item name="colorSecondaryVariant">@color/cbAccentLight</item>
<item name="colorOnSecondary">#FFFFFF</item>
<item name="colorError">@color/cbRed</item>
<item name="android:windowBackground">@color/lightThemeBackground1</item>
</style>
[...]
</resources>
如果我不添加四个受影响的属性,一切正常。我的 minSdkVersion 是 16,compileSdkVersion 和 targetSdkVersion 是 28。我也尝试使用 Bridge 主题,但我得到了同样的错误。我仔细检查了我的依赖项,一切似乎都是正确的。我错过了什么?
【问题讨论】:
-
似乎他们使用了
Theme.AppCompat,如果您仔细read it,我认为它可以与AppCompat主题一起使用,这些是AppCompat的新属性来测试而不是Theme.MaterialComponents: 您还可以增量测试新的 Material 组件而不更改您的应用主题
标签: android android-theme material-components material-components-android