错误:预期颜色但得到(原始字符串)颜色/灰色

时间:2017-11-02 10:27:31

标签: android android-studio styles android-studio-3.0

我已经切换到android studio 3.在我修复了很多问题后,我收到了这个错误:

color / colorPrimary但我去了这个错误:错误:(87,5)错误:预期颜色但得到(原始字符串)颜色/灰色

enter image description here

2 个答案:

答案 0 :(得分:12)

您忘记在@

之前添加 color/colorPrimary

将其更改为 @color/colorPrimary

示例代码

 <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>

答案 1 :(得分:0)

颜色值应该是hex的颜色代码,例如#A5D3F4,或者是带有@符号的颜色引用,例如@color/colorPrimary。使用这些参考之前,必须创建诸如res/values/color.xml之类的资源。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#6200EE</color>
    <color name="colorPrimaryDark">#3700B3</color>
    <color name="colorAccent">#03DAC5</color>
    <color name="LabelColor_text_50">#FFFFFF</color>
    <color name="ValueColor_text_50">#333322</color>
    <color name="LabelColor_bg_50">#A5D3F4</color>
    <color name="ValueColor_bg_50">#E6EEF4</color>
</resources>

并将这些名称用作<item name="someName">@color/LabelColor_text_50</item>