Hoe verander ik de kleur van de Android ListView-scheidingslijn?

Ik wil de kleur van de scheidingslijn ListViewwijzigen. Alle hulp wordt op prijs gesteld.


Antwoord 1, autoriteit 100%

Je kunt deze waarde instellen in een layout-xml-bestand met android:divider="#FF0000". Als je de kleur/tekenkaart verandert, moet je ook de hoogte van de scheidingswand instellen/resetten.

<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>

Antwoord 2, autoriteit 21%

Of je kunt het coderen:

int[] colors = {0, 0xFFFF0000, 0}; // red for the example
myList.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
myList.setDividerHeight(1);

Hopelijk helpt het


Antwoord 3, autoriteit 12%

Gebruik voor een enkele kleurlijn:

list.setDivider(new ColorDrawable(0x99F10529));   //0xAARRGGBB
list.setDividerHeight(1);

Het is belangrijk dat DividerHeight na de scheidingslijn wordt ingesteld, anders krijg je niets.


Antwoord 4, autoriteit 2%

Je kunt de kleuren ook uit je bronnen halen met:

dateView.setDivider(new ColorDrawable(_context.getResources().getColor(R.color.textlight)));
dateView.setDividerHeight(1);

Antwoord 5

XML-versie voor het coole effect van @Asher Aslan.

<?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>

Naam voor die vorm als: list_driver.xml onder tekenbare map

<ListView
        android:id="@+id/category_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:divider="@drawable/list_driver"
        android:dividerHeight="5sp" />

Antwoord 6

Er zijn twee manieren om hetzelfde te doen:

  1. Je kunt de waarde van android:divider=”#FFCCFF”instellen in het layout-xml-bestand.
    Hiermee moet je ook de hoogte van de scheidingslijn specificeren zoals deze 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>
    
  2. U kunt dit ook programmatisch doen…

    ListView listView = getListView();
    ColorDrawable myColor = new ColorDrawable(
        this.getResources().getColor(R.color.myColor)
    );
    listView.setDivider(myColor);
    listView.setDividerHeight();
    

Antwoord 7

Gebruik onderstaande code in uw xml-bestand

<ListView 
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="#000000" 
    android:dividerHeight="1dp">
</ListView> 

Antwoord 8

programmatisch gebruiken

          // Set ListView divider color
            lv.setDivider(new ColorDrawable(Color.parseColor("#FF4A4D93")));
            // set ListView divider height
            lv.setDividerHeight(2);

xml gebruiken

<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="#44CC00"
    android:dividerHeight="4px"/>
</LinearLayout>

Antwoord 9

Gebruik android:divider="#FF0000"en android:dividerHeight="2px"voor ListView.

<ListView 
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#0099FF"
android:dividerHeight="2px"/>

Other episodes