本文翻译自:Android: disabling highlight on listView click
I want to disable the orange highlight that occurs when touching a listView row. 我想禁用触摸listView行时出现的橙色突出显示。 So far in my xml I have tried the following: 到目前为止,在我的xml中我尝试了以下内容:
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. 更多信息:当用户触摸此listView对象的屏幕时,我希望零差异。
#1楼
参考:https://stackoom.com/question/CCKV/Android-禁用listView上的突出显示单击
#2楼
Nothing helps me but this: 什么都没有帮助我,但这:
transparent_drawable.xml
: 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
: layout.xml
:
android:listSelector="@drawable/transparent_drawable"
#3楼
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 RoflcoptrException的答案应该可以解决问题,但由于某些原因它对我不起作用,所以我发布了对我有用的解决方案,希望它可以帮助某人
<ListView
android:listSelector="@android:color/transparent"
android:cacheColorHint="@android:color/transparent"
/>
#4楼
你只需要添加: android:cacheColorHint="@android:color/transparent"
#5楼
in code 在代码中
listView.setSelector(getResources().getDrawable(R.drawable.transparent));
and add small transparent image to drawable folder. 并将小透明图像添加到可绘制文件夹。
Like: transparent.xml 喜欢:transparent.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00000000"/>
</shape>
#6楼
If you are using ArrayAdapter
or BaseAdapter
to populate the list items. 如果您使用ArrayAdapter
或BaseAdapter
填充列表项。 Override
the isEnabled
method and return false
. Override
isEnabled
方法并返回false
。
@Override
public boolean isEnabled (int position) {
return false;
}