Cómo cambiar el color de la línea de separador de Android ListView?
Quiero cambiar el color de la línea separador ListView
. Cualquier ayuda sería apreciada.
8 answers
Puede establecer este valor en un archivo xml de diseño usando android:divider="#FF0000"
. Si va a cambiar el color/dibujable, también tiene que ajustar / restablecer la altura del divisor.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView
android:id="@+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="#FFCC00"
android:dividerHeight="4px"/>
</LinearLayout>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-28 09:20:49
O puedes codificarlo:
int[] colors = {0, 0xFFFF0000, 0}; // red for the example
myList.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
myList.setDividerHeight(1);
Espero que ayude
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-10-10 13:22:28
Para una sola línea de color use:
list.setDivider(new ColorDrawable(0x99F10529)); //0xAARRGGBB
list.setDividerHeight(1);
Es importante que DividerHeight se establezca después del divider, de lo contrario no obtendrá nada.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-12-05 17:35:32
También puedes obtener los colores de tus recursos usando:
dateView.setDivider(new ColorDrawable(_context.getResources().getColor(R.color.textlight)));
dateView.setDividerHeight(1);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-02-08 00:10:08
Versión XML para @Asher Aslan efecto cool.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="180"
android:startColor="#00000000"
android:centerColor="#FFFF0000"
android:endColor="#00000000"/>
</shape>
Nombre para esa forma como: list_driver.xml en la carpeta del elemento de diseño
<ListView
android:id="@+id/category_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@drawable/list_driver"
android:dividerHeight="5sp" />
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-17 16:49:30
Hay dos maneras de hacer lo mismo:
-
Puede establecer el valor de android:divider="#FFCCFF" en el archivo xml de diseño. Con esto también tienes que especificar la altura del divisor así android:dividerHeight="5px ".
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/lvMyList" android:layout_width="match_parent" android:layout_height="match_parent" android:divider="#FFCCFF" android:dividerHeight="5px"/> </LinearLayout>
-
También puede hacer esto mediante programación...
ListView listView = getListView(); ColorDrawable myColor = new ColorDrawable( this.getResources().getColor(R.color.myColor) ); listView.setDivider(myColor); listView.setDividerHeight();
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-02-02 12:32:11
Utilice el siguiente código en su archivo xml
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#000000"
android:dividerHeight="1dp">
</ListView>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-05-15 10:17:05
Use android:divider="#FF0000"
y android:dividerHeight="2px"
para ListView.
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#0099FF"
android:dividerHeight="2px"/>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-17 10:19:44