尝试更改 color.xml 中的颜色后出错 [英] Error after trying to change color in color.xml

查看:23
本文介绍了尝试更改 color.xml 中的颜色后出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习 Android,现在我正在尝试更改我的 android 项目中的颜色.这就是我所做的,

I'm trying to learn Android, now I'm trying to change color in my android project. Here is what I do,

我将 color.xml 更改为:

I change my color.xml to:

<resources>
    <color name="primaryColor">#d81b60</color>
    <color name="primaryLightColor">#ff5c8d</color>
    <color name="primaryDarkColor">#a00037</color>
    <color name="primaryTextColor">#ffffff</color>
</resources>

和我的 style.xml:

and my style.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="primaryColor">@color/primaryColor</item>
    <item name="primaryLightColor">@color/primaryLightColor</item>
    <item name="primaryDarkColor">@color/primaryDarkColor</item>
    <item name="primaryTextColor">@color/primaryTextColor</item>
</style>

但是当我尝试运行时出现此错误:

But when I try to run I get this error(s):

那么,我该如何解决?

我已经试过了:

  1. Android Studio 未找到颜色样式资源

Android Studio 可以't 在同一个资源文件中找到颜色参考

推荐答案

<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

在样式中,这些标签用于指定 colorPrimary 口音和 primaryDark

in style these tags are used to specify the colorPrimary accent and primaryDark

更具体地说,将样式 xml 更改为

to be more specific change the style xml as

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/primaryColor</item> 
        <item name="colorPrimaryDark">@color/primaryDarkColor</item>
        <item name="colorAccent">@color/primaryAcentColor</item>
    </style>

这篇关于尝试更改 color.xml 中的颜色后出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆