configurar el color de fondo en listview

¿Cómo puedo obtener toda mi página de fondo blanca? Tengo un listview e intentado fijar el backgroundcolor blanco en el xml pero no trabajó. Estos son mis xmls:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ListView android:id="@+id/list" android:layout_width="fill_parent" android:clickable="true" android:layout_height="fill_parent"></ListView> 

Lo único que en realidad se pone blanco es esto:

 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/naam" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="10dp" android:textSize="16sp" > </TextView> 

este es mi código java

 public class Contactenlijst extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final HashMap<Integer, Personeel> personeelmap = new HashMap<Integer, Personeel>(); ArrayList<String> list = new ArrayList<String>(); // Get the data (see above) JSONObject json = Database .getJSONfromURL("http://fabian.nostradamus.nu/Android/getcontactinfo.php"); try { JSONArray contactinfo = json.getJSONArray("contactlijst"); // Loop the Array for (int i = 0; i < contactinfo.length(); i++) { JSONObject e = contactinfo.getJSONObject(i); Personeel p = new Personeel( Integer.parseInt(e.getString("id")), e.getString("staff_name"), e.getString("staff_lastname"), e.getString("staff_dateofbirth"), e.getString("staff_address"), e.getString("staff_address_postal"), e.getString("staff_address_city"), e.getString("staff_mobile")); personeelmap.put(Integer.parseInt(e.getString("id")), p); list.add(p.toString()); } } catch (JSONException e) { Log.e("log_tag", "Error parsing data " + e.toString()); } setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, list)); ListView lv = getListView(); lv.setTextFilterEnabled(true); // onclick stuur array naar contactinfo lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String text = ((TextView) view).getText().toString(); Intent i = new Intent(Contactenlijst.this, Contactinfo.class); String uittekst[] = text.split(" "); String vnaam = uittekst[0].toString(); ArrayList<String> al = new ArrayList<String>(); int a = personeelmap.size(); a = a + 1; for (int c = 1; c < a; c++) { if (personeelmap.get(c).getStaff_name().toString() .equals(vnaam)) { al.add(personeelmap.get(c).getStaff_name()); al.add(personeelmap.get(c).getStaff_lastname()); al.add(personeelmap.get(c).getDateofbirth()); al.add(personeelmap.get(c).getStaff_address()); al.add(personeelmap.get(c).getStaff_address_postal()); al.add(personeelmap.get(c).getStaff_address_city()); al.add(personeelmap.get(c).getStaff_mobile()); } ; } i.putStringArrayListExtra("array", al); startActivity(i); } }); } 

}

Hay una manera muy fácil de hacer esto.

Primero, cree una variable ListView en su actividad (sobre onCreate):

 ListView LV = null; 

A continuación, en onCreate para establecer la variable, puede hacer esto, asumiendo que extiende ListActivity:

 LV = getListView(); 

o esto funciona en lugar suponiendo mylist id se establece en XML para el listview:

 LV = (ListView) findViewById(R.id.mylist); 

finalmente, ajuste el fondo a un color:

 LV.setBackgroundColor(Color.WHITE); 

o establecerlo en un drawable:

 int r = getResources().getIdentifier("subtle_white_gradient", "drawable", "com.my.package"); LV.setBackgroundResource(r); 

si desea establecer el color de fondo en el índice '0', U debe ser probar esto funciona bien he utilizado este código.

 list.post(new Runnable() { @Override public void run() { list.setSelected(true); list.setBackgroundColor(Color.BLACK); list.getChildAt(0).setBackgroundColor(Color.BLUE); } }); 

Necesita crear el archivo color.xml en la carpeta res/value de su proyecto. color.xml es

  <?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="black">#000000</color> <color name="gray">#999999</color> <color name="blue">#0066cc</color> </resources> 

Ahora llame a este color en su Lisiview

 <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/blue"/> 

La forma más sencilla es establecer un tema . En el archivo manifest.xml, añada este atributo a su actividad:

 android:theme="@android:style/Theme.Light" 

Pruebe esto en el XML:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ListView android:id="@+id/list" android:layout_width="fill_parent" android:clickable="true" android:layout_height="fill_parent" android:background="@color/background" > </ListView> 

Y cree un archivo XML llamado colors.xml que define el color que desea:

 <color name="background">#CDB38B </string> 
  • Buscar en archivo XML con XPath en Android
  • ListFragment aparece dos veces en el teléfono
  • Android: Refactorización de archivos XML en Eclipse?
  • Android: Utilizar matriz de color en XML
  • Cómo detener la tarea Asyn en onPreExecute?
  • Se ha producido un error de análisis XML de Android Error inesperado
  • Cómo modificar el valor de nodo xml?
  • Los colores de Android no funcionan en mi dispositivo físico
  • Mapbox infla la vista en el fragmento
  • ¿Cómo puedo descompilar archivos dex de forma programática dentro de Android?
  • Java / Android obtener matriz de xml
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.