Android: disabling highlight on listView click

AndroidAndroid ListviewHighlighting

Android Problem Overview


I want to disable the orange highlight that occurs when touching a listView row. So far in my xml I have tried the following:

android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"

More information: I want there to be zero difference when a user touches the screen on this listView object.

Android Solutions


Solution 1 - Android

Add this to your xml:

android:listSelector="@android:color/transparent"

And for the problem this may work (I'm not sure and I don't know if there are better solutions):

You could apply a ColorStateList to your TextView.

Solution 2 - Android

RoflcoptrException's answer should do the trick,but for some reason it did not work for me, So I am posting the solution which worked for me, hope it helps someone

<ListView 
android:listSelector="@android:color/transparent" 
android:cacheColorHint="@android:color/transparent"
/>

Solution 3 - Android

The orange highlight effect is a style on the ListView. This article gives a good overview of how to override the listView style.

Essentially, you have a selector that specifies different style elements based on the current state.

see this for short and quick solution https://stackoverflow.com/a/12242564/185022

Solution 4 - Android

From ListView: Disable Focus Highlight,

when you set your ListAdapter use the following code

ListAdapter adapter = new SimpleCursorAdapter(MyList, Layout, c, 
                new String[] { "Name", "Score" }, to) 
{ 
    public boolean areAllItemsEnabled() 
    { 
        return false; 
    } 
    public boolean isEnabled(int position) 
    { 
        return false; 
    } 
}; 

This will override the BaseAdapter class. It also cancels the white border between cells.

Solution 5 - Android

add this also to ur XMl along with listselector..hope it will work

<ListView
android:cacheColorHint="@android:color/transparent"
android:listSelector="@android:color/transparent"/> 

Solution 6 - Android

If you are using ArrayAdapter or BaseAdapter to populate the list items. Override the isEnabled method and return false.

 @Override
  public boolean isEnabled (int position) {
    return false;
  }

Solution 7 - Android

After a few 'google'ing and testing on virtual and real devices, I notice my below code works:

ArrayAdapter<String> myList = new ArrayAdapter<String>(this, R.layout.list_item, strText) {
    public boolean isEnabled(int position) 
    { 
            return false; 
    } 
};

notice that I've omitted the areAllItemsEnabled() portion.

Solution 8 - Android

Nothing helps me but this:

transparent_drawable.xml:

<?xml version="1.0" encoding="utf-8"?>    
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#00000000"/>
</shape>

layout.xml:

android:listSelector="@drawable/transparent_drawable"

Solution 9 - Android

in code

listView.setSelector(getResources().getDrawable(R.drawable.transparent));

and add small transparent image to drawable folder.

Like: transparent.xml

<?xml version="1.0" encoding="utf-8"?>    
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#00000000"/>
</shape>

Solution 10 - Android

For me android:focusableInTouchMode="true" is the way to go. android:listSelector="@android:color/transparent" is of no use. Note that I am using a custom listview with a number of objects in each row.

Solution 11 - Android

You only need to add: android:cacheColorHint="@android:color/transparent"

Solution 12 - Android

As an alternative:

listView.setSelector(android.R.color.transparent);

or

listView.setSelector(new StateListDrawable());

Solution 13 - Android

There is fast and easy way to do this: In method:

private void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
{
    //TODO
    ((ListView)sender).SelectedItem = null;
}

Hope it'll help ;)

Solution 14 - Android

If you want to disable the highlight for a single list view item, but keep the cell enabled, set the background color for that cell to disable the highlighting.

For instance, in your cell layout, set android:background="@color/white"

Solution 15 - Android

you can just get the pos that you get from the onItemClick and do:

listView.setItemChecked(pos, false);

that's the best way i know of

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohn MoffittView Question on Stackoverflow
Solution 1 - AndroidRoflcoptrExceptionView Answer on Stackoverflow
Solution 2 - AndroidMushtaq JameelView Answer on Stackoverflow
Solution 3 - AndroidCheryl SimonView Answer on Stackoverflow
Solution 4 - Androidemdog4View Answer on Stackoverflow
Solution 5 - AndroidsheetalView Answer on Stackoverflow
Solution 6 - AndroidLibinView Answer on Stackoverflow
Solution 7 - AndroidaerobrainView Answer on Stackoverflow
Solution 8 - AndroidDmitry ChistyakovView Answer on Stackoverflow
Solution 9 - AndroidRobert Bae Dong HwanView Answer on Stackoverflow
Solution 10 - AndroiderdomesterView Answer on Stackoverflow
Solution 11 - AndroidPrakashView Answer on Stackoverflow
Solution 12 - AndroidNataliView Answer on Stackoverflow
Solution 13 - AndroidFeldonDragonView Answer on Stackoverflow
Solution 14 - AndroidGLeeView Answer on Stackoverflow
Solution 15 - AndroidChief MadogView Answer on Stackoverflow