Setting The Background Color of A ListView Through XML
android, eclipse, java, xml
Solution
You can do it this way:
You have to create the Color.xml file in the res/value folder of your project. The code of Color.xml is
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="orange">#ff5500</color>
<color name="white">#ffffff</color>
<color name="transparent">#00000000</color>
<color name="date_color">#999999</color>
<color name="black">#000000</color>
<color name="gray">#999999</color>
<color name="blue">#0066cc</color>
<color name="gold">#e6b121</color>
<color name="blueback">#99FFFF</color>
<color name="articlecolor">#3399FF</color>
<color name="article_title">#3399FF</color>
<color name="cachecolor">#8ad0e8</color>
</resources>
Web colors in an Android color xml resource file
Or, try this:
android:background="@android:color/holo_green_light"
with these colors:
http://developer.android.com/reference/android/R.color.html
Problem
I am aware that I can set the background color of a ListView dynamically through some variation of the following code: ``` ListView mainListView; mainListView = (ListView) findViewById( R.id.listView1 ); mainListView.setBackgroundColor(Color.BLACK); ``` However, I would like to do the identical thing through XML instead. I tried the following code without any luck (it makes no changes): ``` <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="wrap_content" **android:background="#FFFFFF"** android:layout_centerHorizontal="true" android:layout_centerVertical="true" > </ListView> </RelativeLayout> ``` Does anyone know of a simple way to change the background color of a ListView via XML?