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:
Then apply it to the ListView:
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.
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:
And use it in the shape:
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:
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:dividerat 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
RecyclerViewwhen the immediate task is only to style an existingListView.
Summary
- '
ListViewseparator 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.

