如何在android Studio 3.0.1中编辑color.xml

问题描述 投票:1回答:2

我从Android的Color Tool设计了我的颜色文件,并从那里导出了相同的颜色文件。但是当我用现有文件替换文件时。

It is showing the following error stack trace...

Information:Gradle tasks [:app:assembleDebug]
C:\Users\LENOVO\.gradle\caches\transforms-1\files-1.1\appcompat-v7-26.1.0.aar\fe9fe9aedd60d1d8fd516975c2138d20\res\values\values.xml
Error:error: style attribute 'attr/colorPrimaryLight (aka com.example.lenovo.jdstudio:attr/colorPrimaryLight)' not found.
Error:error: style attribute 'attr/colorSecondary (aka com.example.lenovo.jdstudio:attr/colorSecondary)' not found.
Error:error: style attribute 'attr/colorSecondaryLight (aka com.example.lenovo.jdstudio:attr/colorSecondaryLight)' not found.
Error:error: style attribute 'attr/colorSecondaryDark (aka com.example.lenovo.jdstudio:attr/colorSecondaryDark)' not found.
Error:error: style attribute 'attr/primaryTextColor (aka com.example.lenovo.jdstudio:attr/primaryTextColor)' not found.
Error:error: style attribute 'attr/secondaryTextColor (aka com.example.lenovo.jdstudio:attr/secondaryTextColor)' not found.
F:\JDStudio\code\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml
Error:(1899) style attribute 'attr/colorPrimaryLight (aka com.example.lenovo.jdstudio:attr/colorPrimaryLight)' not found.
Error:(1901) style attribute 'attr/colorSecondary (aka com.example.lenovo.jdstudio:attr/colorSecondary)' not found.
Error:(1902) style attribute 'attr/colorSecondaryLight (aka com.example.lenovo.jdstudio:attr/colorSecondaryLight)' not found.
Error:(1903) style attribute 'attr/colorSecondaryDark (aka com.example.lenovo.jdstudio:attr/colorSecondaryDark)' not found.
Error:(1904) style attribute 'attr/primaryTextColor (aka com.example.lenovo.jdstudio:attr/primaryTextColor)' not found.
Error:(1905) style attribute 'attr/secondaryTextColor (aka com.example.lenovo.jdstudio:attr/secondaryTextColor)' not found.
Error:failed linking references.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt
Information:BUILD FAILED in 57s
Information:17 errors
Information:0 warnings
Information:See complete output in console

Deafault colors.xml file is

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3f51b5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="content">#F5F5F5</color>>
</resources>

The one which I want to replace

<?xml version="1.0" encoding="UTF-8"?>
<resources>
  <color name="colorPrimary">#0091ea</color>
  <color name="colorPrimaryLight">#64c1ff</color>
  <color name="colorPrimaryDark">#0064b7</color>
  <color name="colorSecondary">#263238</color>
  <color name="colorSecondaryLight">#4f5b62</color>
  <color name="colorSecondaryDark">#000a12</color>
  <color name="primaryTextColor">#fafafa</color>
  <color name="secondaryTextColor">#ffffff</color>
</resources>

styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryLight">@color/colorPrimaryLight</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorSecondary">@color/colorSecondary</item>
        <item name="colorSecondaryLight">@color/colorSecondaryLight</item>
        <item name="colorSecondaryDark">@color/colorSecondaryDark</item>
        <item name="primaryTextColor">@color/primaryTextColor</item>
        <item name="secondaryTextColor">@color/secondaryTextColor</item>
    </style>
</resources>

I also tried to change android:theme attribute in the AndroidMainfest.xml file like

android:theme="@style/MyAppTheme"    
android xml android-studio
2个回答
0
投票

我想你可以使用android studio style编辑器。它更简单并自动改变您的颜色。您应该在style.xml中定义样式并在color.xml中定义颜色,也不要用原始文件替换文件,否则可能会出现很多错误。


0
投票

您需要将此行放在colors.xml中

<color name="colorAccent">#FF4081</color>

或者你需要另一种颜色作为style.xml中的强调色。

<style name="AppTheme_Light" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/abc1</item>
    <item name="colorPrimaryDark">@color/abc2</item>
    <item name="colorAccent">@color/abc3</item>
</style>

快乐编码:)

© www.soinside.com 2019 - 2024. All rights reserved.