[英]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.