I want to disable the highlight that appears when the user selects a row (listSelector) from code. I don't want to disable the onClick and enabled settings (I still want to listen to clicks, just want to remove the highlight).
-
Which adapter are you using? – Dmitry Guselnikov Jun 10 '13 at 21:45
-
A simple ArrayAdapter
. Will it matter? – Abdalrahman Shatou Jun 10 '13 at 21:46 -
1"I want to disable the highlight that appears when the user selects a row" -- why? What about the users that use arrow keys, D-pad, and the like for navigating your app? Please allow your app to be used by *all* users, not just those who use the touchscreen. – CommonsWare Jun 10 '13 at 21:52
-
http://stackoverflow.com/a/4075045/1005846. Hope it will help – Dmitry Guselnikov Jun 10 '13 at 21:53
-
1@CommonsWare well, I don't want to support hard keyboard and I won't :) – Abdalrahman Shatou Jun 10 '13 at 22:00
5 Answers
Specify android:listSelector="@android:color/transparent"
in your ListView
XML.

- 3,420
- 2
- 30
- 46
Just create a drawable that has a transparent color in it, something like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:drawable="@android:color/transparent"/>
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_disabled_holo_light" />
<item android:state_focused="true" android:state_enabled="false" android:drawable="@drawable/list_selector_disabled_holo_light" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@color/transparent" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@color/transparent" />
<item android:state_focused="true" android:drawable="@drawable/list_focused_holo" />
</selector>
And then set by code or by XML:
listView.setSelector(R.drawable.my_transparent_selector);
The javadoc for this method says:
Set a Drawable that should be used to highlight the currently selected item.
and the XML attribute is:
android:listSelector
You can play with all the states, remember that you also have the focus state.

- 1,783
- 1
- 17
- 26

- 2,661
- 2
- 24
- 30
-
From code, Nicolas, not the XML. I can handle it already from XML using listSelector attribute. – Abdalrahman Shatou Jun 10 '13 at 21:49
-
I do not know why you need in that way, so keep two files and play with them. – Nicolas Jafelle Jun 10 '13 at 21:53
-
No, after edit, it's working fine. I am using a some sort of checkbox instead of row highlight. Your answer works like a charm. Thanks. – Abdalrahman Shatou Jun 10 '13 at 21:59
I have done this way:
By adding two properties of ListView.
android:cacheColorHint="@android:color/transparent"
android:listSelector="@android:color/transparent"
Your ListView should looks like below:
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="@android:color/transparent"
android:listSelector="@android:color/transparent">
</ListView>
Done

- 52,124
- 21
- 173
- 151
try listview.setSelector(new ColorDrawable(Color.TRANSPARENT));

- 1,077
- 2
- 13
- 14
-
This one was easiest for me, who goes for a programmatic approach thanks. – Zhang Feb 04 '16 at 08:39
The highlight effect is a style on the listSelector. You can override the listSelector style.
This is a example with a listview : Android: disabling highlight on listView click

- 1
- 1