简体   繁体   English

Android Color Drawable Resource

[英]Android Color Drawable Resource

I have the following colors: 我有以下颜色:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <drawable name="darkgray">#404040ff</drawable>
  <drawable name="black">#000ff</drawable>
  <drawable name="red">#ff00ff</drawable>
  <drawable name="green">#0ff0ff</drawable>
  <drawable name="lightgray">#c0c0c0ff</drawable>
  <drawable name="white">#ffffffff</drawable>
  <drawable name="yellow">#ffff0ff</drawable>
  <drawable name="blue">#00ffff</drawable>
  <drawable name="gray">#808080ff</drawable>
  <drawable name="magenta">#ff0ffff</drawable>
  <drawable name="cyan">#0ffffff</drawable>
</resources>

And I have the following in my Main Layout file for a Button background color: (snippet) 我在主要布局文件中有以下按钮背景颜色:(片段)

<Button
  android:id="@+id/widget27"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="@drawable/yellow"
  android:text="Button"
  android:layout_x="30px"
  android:layout_y="102px"
>
</Button>

My question is: What do I name the file with the colors, and where do I put it? 我的问题是:我用文字命名文件,我在哪里放? I am getting a compile error, aresgen exit error. 我收到编译错误,aresgen退出错误。

I'm looking for a filename and location where the background colors can be accessed. 我正在寻找可以访问背景颜色的文件名和位置。

Thanks, 谢谢,

You should create an XML file at in res/values/colors.xml -- store all your colors in here. 您应该在res/values/colors.xml创建一个XML文件 - 将所有颜色存储在此处。

Additionally, you should read this whole page, but here is the section that directly relates to your question: 此外,您应该阅读整个页面,但这里是与您的问题直接相关的部分:

http://developer.android.com/guide/topics/resources/more-resources.html#Color http://developer.android.com/guide/topics/resources/more-resources.html#Color

First of all you have forgotten, that Button is closed like this 首先你已经忘记了,按钮是这样关闭的

<Button
  android:id="@+id/widget27"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="@drawable/yellow"
  android:text="Button"
  android:layout_x="30px"
  android:layout_y="102px"
/>

and next you can use this instead of your code 接下来你可以使用它来代替你的代码

<Button
  android:id="@+id/widget27"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="@android:color/white"
  android:text="Button"
  android:layout_x="30px"
  android:layout_y="102px"
/>

but if you want to use your color use this link 但如果你想使用你的颜色,请使用此链接

http://android-er.blogspot.com/2010/03/using-color-in-android.html http://android-er.blogspot.com/2010/03/using-color-in-android.html

try this on the xml 在xml上试试这个

<color name="white">#FFFFFF</color>

and on your button 并在你的按钮上

<Button
  android:id="@+id/widget27"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="@color/white"
  android:text="Button"
  android:layout_x="30px"
  android:layout_y="102px"
/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM