错误:找不到样式属性'attr/colorPrimary'



最近,我根据新的Android指南将目标SDK更新为29,但之后我收到了这个错误:

D:\Android Apps\PatherPane\app\src\main\res\values\styles.xml:4:5-9:13:AAPT:错误:找不到样式属性"attr/colorPrimary(又名com.PatherPane.app:attr/colorPrimari("。

我的风格XML文件是:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="SplashScreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">
@drawable/background_splashscreen
</item>
</style>

我该怎么解决这个问题?

此命令后面跟有项目名称,显示错误:Theme.AppCompat.Light.DarkActionBar

确保您没有错过build.gradle(app(中的appcompat实现

implementation ‘com.android.support:appcompat-v7:28.0.0’

implementation 'androidx.appcompat:appcompat:1.2.0'

如果使用androidx

在一个库模块中有这个问题,该模块突然停止解析主题。

dependencies {
implementation "com.google.android.material:material:1.3.0"
}

此错误通常在时显示

androidx.appcompat:appcompat

com.google.android.material:material

版本不匹配。检查您是否更新了一个而不是另一个

转到app/src/main/res/values/colors.xml它应该看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>  //This is where the colorPrimary is defined
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
</resources>

请确保我注释的行存在,具有正确的语法,并在在中间定义了适当的6位六进制代码。六进制代码应该是你正在设计的主题的原色。

最新更新