Android:禁用listView上的突出显示单击

本文翻译自: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. 如果您使用ArrayAdapterBaseAdapter填充列表项。 Override the isEnabled method and return false . Override isEnabled方法并返回false

 @Override
  public boolean isEnabled (int position) {
    return false;
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值