Change listview separator line color in android example

How to modify color to listview divider line using layout xml file and define Photoshop color.

ListView separator line is the main divider line which displays after every list element and separate the above list item to below list item. By default ListView separator line color is like light black but app developer can modify the listview separator line color using android:divider=”  “ attribute in listview widget inside activity_main.xml layout file. So here is the complete step by step tutorial for Change listview separator line color in android example.

android-project-download-code-button

How to Change listview separator line color in android example.

Code for MainActivity.java file.

 package com.example.listviewseparatorlinecolor_android_examples.com;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {

 ListView listViewSeparator ;
 String[] listviewValue = new String[] 
 {"ONE",
 "TWO",
 "THREE",
 "FOUR"
 ,"FIVE",
 "SIX"};
 
 @Override
 protected void onCreate(Bundle savedInstanceState) 
 {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 listViewSeparator = (ListView)findViewById(R.id.listView1);
 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_2, android.R.id.text1, listviewValue);
 
 listViewSeparator.setAdapter(adapter); 
 
 
 
 }
 }

Code for activity_main.xml layout file.

 <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"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.example.listviewseparatorlinecolor_android_examples.com.MainActivity" >

 <ListView
 android:id="@+id/listView1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:divider="#fd0012"
 android:dividerHeight="3dp" >
 </ListView>

</RelativeLayout>

Screenshot:

Change listview separator line color in android example

Click here to download Change listview separator line color in android example project.

Leave a Reply

Your email address will not be published. Required fields are marked *