如何在androidStudio 3.0.1中编辑color.xml [英] How to edit the color.xml in androidStudio 3.0.1

查看:131
本文介绍了如何在androidStudio 3.0.1中编辑color.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从Android的颜色工具设计了我的颜色文件,并从那里导出了相同的颜色文件.但是当我用现有文件替换文件时.

I have designed my color file from the Color Tool from android and exported the same from there. But when I replace the file with the existing one.

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

默认的colors.xml文件是

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

我要替换的那个

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

我还试图更改AndroidMainfest.xml文件中的android:theme属性,例如

android:theme="@style/MyAppTheme"    

推荐答案

我认为您可以使用android studio样式编辑器.它更简单,可以自动更改颜色.您应该在 style.xml 中定义样式,并在 color.xml 中定义颜色并且不要用原始文件替换文件,您可能会遇到很多错误.

I think you can use android studio style editor. It is more simple and automatically change your colors. You should define your style in style.xml and define colors in color.xml and also don't replace files with the original one you may get lots of errors.

这篇关于如何在androidStudio 3.0.1中编辑color.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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