Reputation: 5839
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.
Upvotes: 312
Views: 182930
Reputation: 2015
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.
Upvotes: 64
Reputation: 52249
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.
Upvotes: 688
Reputation: 131
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"
Upvotes: 11
Reputation: 21
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 ;)
Upvotes: 1
Reputation: 131
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>
Upvotes: 7
Reputation: 2972
As an alternative:
listView.setSelector(android.R.color.transparent);
or
listView.setSelector(new StateListDrawable());
Upvotes: 4
Reputation: 1507
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
Upvotes: 0
Reputation: 5093
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"
Upvotes: 0
Reputation: 3064
add this also to ur XMl along with listselector..hope it will work
<ListView
android:cacheColorHint="@android:color/transparent"
android:listSelector="@android:color/transparent"/>
Upvotes: 40
Reputation: 46844
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
Upvotes: 101
Reputation: 17095
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;
}
Upvotes: 31
Reputation: 7083
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"
/>
Upvotes: 190
Reputation: 51
You only need to add:
android:cacheColorHint="@android:color/transparent"
Upvotes: 5
Reputation: 11829
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.
Upvotes: 6
Reputation: 623
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.
Upvotes: 13