Android
ListView
Separator Line
UI Customization
Android Development

How to change color of Android ListView separator line?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Changing a ListView separator color in Android is usually a matter of replacing the default divider drawable, not calling some special “set separator color” API. The most maintainable approach is to use a shape drawable in XML and assign it with the android:divider attribute. Even though ListView is older UI infrastructure, the same rule still applies: separators are drawables, so style them as drawables.

The Simplest XML-Based Solution

Define a divider drawable in res/drawable/list_divider.xml:

xml
1<?xml version="1.0" encoding="utf-8"?>
2<shape xmlns:android="http://schemas.android.com/apk/res/android">
3    <size android:height="1dp" />
4    <solid android:color="@android:color/holo_blue_light" />
5</shape>

Then apply it to the ListView:

xml
1<ListView
2    android:id="@+id/my_list"
3    android:layout_width="match_parent"
4    android:layout_height="match_parent"
5    android:divider="@drawable/list_divider"
6    android:dividerHeight="1dp" />

This is the most common solution because it is simple, themeable, and easy to change later.

Why a Drawable Is Better Than a Hardcoded Color

You may be tempted to point android:divider directly at a color resource. In practice, a shape drawable is more flexible because it lets you control:

  • thickness,
  • insets via padding or layer-list composition,
  • different styling for themes,
  • future changes without touching layout files.

That flexibility matters when a design evolves from a plain line into something slightly richer.

Setting the Divider Programmatically

If the separator color depends on runtime conditions, assign the divider in code.

kotlin
val listView = findViewById<ListView>(R.id.my_list)
listView.divider = getDrawable(R.drawable.list_divider)
listView.dividerHeight = resources.getDimensionPixelSize(R.dimen.list_divider_height)

This is useful for:

  • feature flags,
  • brand themes loaded at runtime,
  • debug or admin screens with different styling.

For ordinary app theming, XML remains cleaner.

Theme-Aware Divider Colors

If the app supports light and dark modes, make the divider color theme-aware instead of hardcoding a single hex value.

Example color resource:

xml
<color name="list_divider_color">#D0D7DE</color>

And use it in the shape:

xml
<solid android:color="@color/list_divider_color" />

With day and night resource folders, the separator changes automatically with the active theme.

Remove or Soften the Divider When Needed

Sometimes the correct answer is not “change the color,” but “remove the line” or make it less visually heavy.

To remove the divider entirely:

xml
1<ListView
2    android:layout_width="match_parent"
3    android:layout_height="match_parent"
4    android:divider="@null"
5    android:dividerHeight="0dp" />

Or use a subtle low-contrast color in the drawable for a softer list appearance.

A Note on RecyclerView

If you are working on a modern screen, consider whether the UI should still use ListView at all. RecyclerView is more flexible and handles item decoration differently. But if the codebase already uses ListView, changing the divider drawable is still the right fix for separator color.

Do not force a component migration just to recolor a separator.

Common Pitfalls

  • Pointing android:divider at the wrong resource type and then wondering why the line does not render as expected.
  • Forgetting to set android:dividerHeight, which can make a custom divider hard to see.
  • Hardcoding a color that looks fine in one theme but clashes badly in dark mode.
  • Trying to solve the problem in adapter code even though divider styling belongs to the ListView.
  • Spending time modernizing to RecyclerView when the immediate task is only to style an existing ListView.

Summary

  • 'ListView separator color is controlled by the divider drawable.'
  • The cleanest solution is a shape drawable assigned through android:divider.
  • Use XML for static styling and programmatic assignment only when runtime control is needed.
  • Make divider colors theme-aware if the app supports multiple themes.
  • If the UI is already built on ListView, recoloring the divider does not require changing the whole list architecture.

Course illustration
Course illustration

All Rights Reserved.