繁体   English   中英

Android Color Drawable Resource

[英]Android Color Drawable Resource

我有以下颜色:

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

我在主要布局文件中有以下按钮背景颜色:(片段)

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

我的问题是:我用文字命名文件,我在哪里放? 我收到编译错误,aresgen退出错误。

我正在寻找可以访问背景颜色的文件名和位置。

谢谢,

您应该在res/values/colors.xml创建一个XML文件 - 将所有颜色存储在此处。

此外,您应该阅读整个页面,但这里是与您的问题直接相关的部分:

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

首先你已经忘记了,按钮是这样关闭的

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

但如果你想使用你的颜色,请使用此链接

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

在xml上试试这个

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

并在你的按钮上

<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