Android:禁用列表视图点击上的突出显示
我想禁用触摸 listView 行时出现的橙色突出显示。到目前为止,在我的 xml 中,我已经尝试了以下操作:
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
更多信息:我希望当用户触摸此 listView 对象上的屏幕时差异为零。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
将其添加到您的 xml 中:
对于这个问题,这可能有效(我不确定,也不知道是否有更好的解决方案):
您可以应用 ColorStateList 到您的 TextView。
Add this to your xml:
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.
RoflcoptrException 的答案应该可以解决问题,但由于某种原因它对我不起作用,所以我发布了对我有用的解决方案,希望它可以帮助别人
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 上的 样式。 这篇文章很好地概述了如何覆盖listView样式。
本质上,您有一个根据当前状态指定不同样式元素的选择器。
请参阅此简短快速的解决方案https://stackoverflow.com/a/12242564/185022
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
来自 ListView:禁用焦点突出显示:
当您设置时您的
ListAdapter
使用以下代码:这将覆盖
BaseAdapter
类。它还取消了单元格之间的白色边框。From ListView: Disable Focus Highlight:
When you set your
ListAdapter
use the following code:This will override the
BaseAdapter
class. It also cancels the white border between cells.将其与列表选择器一起添加到您的 XMl 中。希望它能工作
add this also to ur XMl along with listselector..hope it will work
如果您使用 ArrayAdapter 或 BaseAdapter 来填充列表项。
重写
isEnabled
方法并返回false
。If you are using
ArrayAdapter
orBaseAdapter
to populate the list items.Override
theisEnabled
method and returnfalse
.在虚拟和真实设备上进行几次“谷歌”搜索和测试后,我注意到下面的代码有效:
请注意,我省略了
areAllItemsEnabled()
部分。After a few 'google'ing and testing on virtual and real devices, I notice my below code works:
notice that I've omitted the
areAllItemsEnabled()
portion.除了这个之外没有什么可以帮助我:
transparent_drawable.xml
:layout.xml
:Nothing helps me but this:
transparent_drawable.xml
:layout.xml
:在代码中
并将小透明图像添加到可绘制文件夹中。
喜欢:
透明.xml
in code
and add small transparent image to drawable folder.
Like:
transparent.xml
对我来说
android:focusableInTouchMode="true"
是要走的路。android:listSelector="@android:color/transparent"
没有用。请注意,我使用的是自定义列表视图,每行中有多个对象。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.您只需要添加:
android:cacheColorHint="@android:color/transparent"
You only need to add:
android:cacheColorHint="@android:color/transparent"
作为替代方案:
或
As an alternative:
or
有一种快速而简单的方法可以做到这一点:
在方法中:
希望它会有所帮助;)
There is fast and easy way to do this:
In method:
Hope it'll help ;)
如果要禁用单个列表视图项的突出显示,但保持单元格启用,请设置该单元格的背景颜色以禁用突出显示。
例如,在单元格布局中,设置
android:background="@color/white"
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"
您只需获取从
onItemClick
获取的pos
并做:
这是我所知道的最好的方法
you can just get the
pos
that you get from theonItemClick
and do:
that's the best way i know of