Android
ListView
UI Design
Highlight
Mobile Development

Android disabling highlight on listView click

Master System Design with Codemia

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

Introduction

ListView shows a pressed or selected highlight because Android applies a selector drawable when the user touches a row. If you want the click to perform its action without changing the row background, you need to replace or neutralize that selector instead of fighting the behavior from inside the adapter.

Where the Highlight Comes From

The visual flash is usually controlled by the list selector, not by the onItemClick callback itself. ListView draws the selector over or behind the row to indicate pressed, focused, or selected state.

That is why clearing the background inside getView() usually does not solve the problem. The view may still be drawn with the selector when touched.

The quickest XML solution is to set a transparent selector on the ListView:

xml
1<ListView
2    android:id="@+id/listView"
3    android:layout_width="match_parent"
4    android:layout_height="match_parent"
5    android:listSelector="@android:color/transparent" />

This tells the ListView to keep handling clicks normally while drawing no visible highlight.

Use a Custom Selector When You Need More Control

A fully transparent selector is fine if you want no pressed-state feedback at all. If you want finer control, define your own selector drawable and point android:listSelector at it.

Create res/drawable/list_selector.xml:

xml
1<?xml version="1.0" encoding="utf-8"?>
2<selector xmlns:android="http://schemas.android.com/apk/res/android">
3    <item android:state_pressed="true" android:drawable="@android:color/transparent" />
4    <item android:state_focused="true" android:drawable="@android:color/transparent" />
5    <item android:drawable="@android:color/transparent" />
6</selector>

Then use it:

xml
1<ListView
2    android:id="@+id/listView"
3    android:layout_width="match_parent"
4    android:layout_height="match_parent"
5    android:listSelector="@drawable/list_selector" />

This is more explicit and easier to extend if you later decide to show a subtle pressed state instead of none at all.

Programmatic Alternative

If you need to control this in code, set the selector directly:

java
ListView listView = findViewById(R.id.listView);
listView.setSelector(android.R.color.transparent);

That is useful when the same screen can switch between selectable and non-selectable modes. The behavior is the same as the transparent XML selector, but the setting is applied at runtime.

Watch for Row Backgrounds and Clickable Children

If the highlight still appears after changing listSelector, the row layout itself may be drawing a stateful background. For example, a row root view with its own selector or ripple background can still show a pressed effect even when the ListView selector is transparent.

A minimal row layout that stays visually neutral looks like this:

xml
1<TextView xmlns:android="http://schemas.android.com/apk/res/android"
2    android:id="@+id/title"
3    android:layout_width="match_parent"
4    android:layout_height="wrap_content"
5    android:padding="16dp"
6    android:background="@android:color/transparent"
7    android:textColor="@android:color/black" />

Also check whether child views are focusable or clickable. Buttons and other interactive children can interfere with row touch handling and create state behavior that looks like a list highlight issue.

Keep Usability in Mind

Removing all feedback is sometimes the right visual choice, but it has a cost. Pressed-state feedback helps users understand that their tap was registered. If you disable the highlight, consider whether another signal should remain, such as:

  • opening the next screen immediately
  • animating the touched content slightly
  • showing a subtle custom background change instead of a full highlight

If the list is purely decorative and item taps are secondary, a transparent selector may be appropriate. If the list is the main interaction surface, completely removing feedback can make the interface feel unresponsive.

A Complete Example

Here is a simple activity setup that keeps click behavior but removes visible highlight:

java
1import android.app.Activity;
2import android.os.Bundle;
3import android.widget.ArrayAdapter;
4import android.widget.ListView;
5import android.widget.Toast;
6
7public class MainActivity extends Activity {
8    @Override
9    protected void onCreate(Bundle savedInstanceState) {
10        super.onCreate(savedInstanceState);
11        setContentView(R.layout.activity_main);
12
13        ListView listView = findViewById(R.id.listView);
14        listView.setSelector(android.R.color.transparent);
15
16        String[] items = {"Alpha", "Beta", "Gamma"};
17        ArrayAdapter<String> adapter = new ArrayAdapter<>(
18            this,
19            android.R.layout.simple_list_item_1,
20            items
21        );
22
23        listView.setAdapter(adapter);
24        listView.setOnItemClickListener((parent, view, position, id) ->
25            Toast.makeText(this, "Clicked: " + items[position], Toast.LENGTH_SHORT).show()
26        );
27    }
28}

The click still fires normally. Only the visual highlight is removed.

Common Pitfalls

The most common mistake is changing the item view background in the adapter and expecting that to override the ListView selector. Another is setting a transparent listSelector but forgetting that the row layout itself may still have a pressed-state drawable or ripple. Developers also sometimes remove all feedback without considering usability, which makes taps feel broken even though the click handler is working. A final issue is confusing row selection state with focusable child views that intercept touches and create different visual behavior.

Summary

  • 'ListView highlight is usually controlled by the selector, not by the click handler.'
  • Use android:listSelector="@android:color/transparent" to remove the visible highlight quickly.
  • Use a custom selector drawable when you want explicit control over pressed and focused states.
  • If highlight remains, inspect the row layout background and any clickable child views.
  • Disabling feedback is easy technically, but make sure the UI still feels responsive to the user.

Course illustration
Course illustration

All Rights Reserved.