2011-05-21 65 views
13

我有以下顏色:Android的顏色繪製資源

<?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退出錯誤。

我正在尋找可以訪問背景顏色的文件名和位置。

感謝,

回答

2

你已經忘記了,首先,該按鈕被關閉這樣

<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

+0

簡化版,它的工作? – George 2011-05-23 07:03:51

1

嘗試這種對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" 
/> 
相關問題