Cómo cambiar el color del divisor en el listview?
Necesito cambiar el color del divisor en el listview. El código que estoy usando para lograr esto se cita a continuación:
<ListView android:id="@+id/restaurant_list_widget" android:layout_width="1px" android:layout_height="1px" android:layout_weight="1" android:background="@drawable/list" android:divider="#FFFFFF" android:dividerHeight="4px"> </ListView>
Todavía consigo un divisor ancho negro de 1px. ¿Qué estoy haciendo mal?
Actualización: ListItem
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="5dp" android:background="@color/list_background"> <TextView android:id="@+id/restaurant_list_item_name" android:layout_marginBottom="4dp" android:textStyle="bold" android:textSize="15dp" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textColor="#fff" android:text="Restaurant Name Goes Here"></TextView> <TextView android:id="@+id/restaurant_list_item_detail" android:textSize="10dp" android:layout_width="fill_parent" android:layout_height="fill_parent"></TextView> </LinearLayout>
Lo he probado con:
<ListView android:id="@+id/ListView01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:divider="@color/redBackground" android:dividerHeight="1dip"> </ListView>
Y el valor del color está dentro de colors.xml:
<color name="redBackground">#C60202</color>
Y su funcionamiento fino y exhibiendo el color del divisor como rojo con la altura 1dip.
Actualizar:
Sólo comprueba tu presentación listview, has mencionado 1px para layout_width
y layout_height
y estás configurando 4px para el dividerHeight
.
Creo que el problema está en el layout_width
& layout_height
.
Establecer layout_width="fill_parent"
y layout_height="wrap_content"
De otra manera
Formas de establecer el color y la altura del divisor en ListView
-
Puede establecer este valor en un archivo xml de diseño utilizando
android:divider="#FF0000"
. -
También debe establecer / restablecer la altura del divisor cuando lo modifique.
<ListView android:id="@+id/android:list" android:layout_width="wrap_content" android:layout_height="wrap_content" android:divider="#FFCC00" android:dividerHeight="4px"/>
-
También puede especificar un recurso
Drawable
enandroid:divider
también. -
Puede codificarlo:
int[] colors = {0, 0xFFFF0000, 0}; // red for the example myList.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors)); myList.setDividerHeight(1);
-
Puedes hacer como
Método 1:
En res / values / colors.xml, ponga lo siguiente:
<resources> <color name="sage">#cceebb</color> </resources>
En su clase ListActivity ListActivity
extensible, haga lo siguiente:
ListView lv = getListView(); ColorDrawable sage = new ColorDrawable(this.getResources().getColor(R.color.sage)); lv.setDivider(sage); lv.setDividerHeight(1);
Método 2:
En res / values / colors.xml:
<resources> <drawable name="sage">#cceebb</drawable> </resources>
Y en tu clase que extiende ListActivity:
ListView lv = getListView(); ColorDrawable sage = new ColorDrawable(this.getResources().getColor(R.drawable.sage)); lv.setDivider(sage); lv.setDividerHeight(1);
Espero eso ayude
Sólo necesita establecer los atributos de divisor de ListView:
android:divider="#FFCC00"
Debe agregar el código siguiente en ListView:
android:divider="@android:color/white" android:dividerHeight="0.2dp"
Un enfoque diferente está en tus estilos.xml solo agrega a la etiqueta de estilo
<item name="android:divider">#B6B6B6</item>
p.ej:
<style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimaryDark">#303F9F</item> <item name="colorPrimary">#3F51B5</item> <item name="colorAccent">#FF5722</item> <item name="android:textColorPrimary">@color/textColorPrimary</item> <item name="android:textColorSecondary">@color/textColorSecondary</item> <item name="android:divider">#B6B6B6</item> <item name="android:windowBackground">@color/window_background</item> </style>
Debe agregar el siguiente código.
<ListView android:id="@+id/restaurant_list_widget" android:layout_width="match_parent" android:layout_height="match_parent" android:divider="#FFFFFF" android:dividerHeight="0.5dp" />