【问题标题】:error: style attribute 'attr/colorPrimary' not found错误:未找到样式属性“attr/colorPrimary”
【发布时间】:2020-08-20 19:28:21
【问题描述】:

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

D:\Android Apps\PatherPane\app\src\main\res\values\styles.xml:4:5-9:13: AAPT: error: style attribute 'attr/colorPrimary (aka com.patherpane.app :attr/colorPrimary)' 未找到。

我的样式 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

【问题讨论】:

    标签: android xml android-studio


    【解决方案1】:

    确保您没有错过 build.gradle(app)

    中的 appcompat 实现
    implementation ‘com.android.support:appcompat-v7:28.0.0’
    

    implementation 'androidx.appcompat:appcompat:1.2.0'
    

    如果使用 androidx

    【讨论】:

      【解决方案2】:

      这个错误通常出现在

      androidx.appcompat:appcompat
      

      com.google.android.material:material
      

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

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

          【解决方案4】:

          转到 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 位十六进制代码。 hexcode 应该是您正在设计的主题的原色。

          【讨论】:

          • 你好,这就是我已经在颜色文件中的内容,但我正在谈论样式文件
          猜你喜欢
          • 2018-01-19
          • 1970-01-01
          • 1970-01-01
          • 2019-06-10
          • 2018-01-16
          • 2020-07-04
          • 1970-01-01
          • 2023-03-24
          相关资源
          最近更新 更多