我尝试从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主题,但我得到了相同的错误。我仔细检查了我的依赖项,一切似乎都是正确的。我遗漏了什么?
发布于 2018-11-11 18:02:35
看起来1.1.0 (目前在alpha中)已经解决了这个问题:
implementation 'com.google.android.material:material:1.1.0-alpha09'发布于 2018-10-05 04:54:45
我刚刚检查了the documentation和你用过的东西。它似乎仍然没有添加到Theme.MaterialComponents中,也不能与该主题一起工作。
(通过使用 Theme.MaterialComponents__)也出现未找到错误)
有趣的是,我认为它应该与parent="Theme.AppCompat"一起工作,因为他们说这是为了测试它是如何工作的:
您还可以在不更改应用程序主题的情况下增量测试新材料组件。这使您可以保持现有布局的外观和行为不变,同时一次向您的布局中引入一个新组件。
阅读: AppCompat Themes
https://stackoverflow.com/questions/52654615
复制相似问题