Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

I'm looking for a filename and location where the background colors can be accessed.

Thanks,

like image 945
Trey Avatar asked May 21 '11 16:05

Trey


People also ask

What is color drawable android?

android.graphics.drawable.ColorDrawable. A specialized Drawable that fills the Canvas with a specified color. Note that a ColorDrawable ignores the ColorFilter. It can be defined in an XML file with the <color> element.

How do you tint a drawable android?

You can use android:drawableTint="@color/yourColor" in >23 android version.

How do I change the color of a drawable in XML?

Use app:drawableTint="@color/yourColor" in the xml instade android:drawableTint="@color/yourColor" . It has the backward compatibility.


Video Answer


1 Answers

You should create an XML file at in res/values/colors.xml -- store all your colors in here.

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

like image 146
hwrdprkns Avatar answered Sep 30 '22 10:09

hwrdprkns