Android:禁用列表视图点击上的突出显示

发布于 2024-09-02 12:22:00 字数 222 浏览 7 评论 0原文

我想禁用触摸 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

糖果控 2024-09-09 12:22:00

将其添加到您的 xml 中:

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

对于这个问题,这可能有效(我不确定,也不知道是否有更好的解决方案):

您可以应用 ColorStateList 到您的 TextView。

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.

池予 2024-09-09 12:22:00

RoflcoptrException 的答案应该可以解决问题,但由于某种原因它对我不起作用,所以我发布了对我有用的解决方案,希望它可以帮助别人

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

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"
/>
涫野音 2024-09-09 12:22:00

橙色高亮效果是 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

许你一世情深 2024-09-09 12:22:00

来自 ListView:禁用焦点突出显示

当您设置时您的 ListAdapter 使用以下代码:

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

这将覆盖 BaseAdapter 类。它还取消了单元格之间的白色边框。

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.

夏の忆 2024-09-09 12:22:00

将其与列表选择器一起添加到您的 XMl 中。希望它能工作

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

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

<ListView
android:cacheColorHint="@android:color/transparent"
android:listSelector="@android:color/transparent"/> 
千仐 2024-09-09 12:22:00

如果您使用 ArrayAdapter 或 BaseAdapter 来填充列表项。 重写 isEnabled 方法并返回false

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

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;
  }
悲欢浪云 2024-09-09 12:22:00

在虚拟和真实设备上进行几次“谷歌”搜索和测试后,我注意到下面的代码有效:

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

请注意,我省略了 areAllItemsEnabled() 部分。

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.

入画浅相思 2024-09-09 12:22:00

除了这个之外没有什么可以帮助我:

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"

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"
鹊巢 2024-09-09 12:22:00

在代码中

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

并将小透明图像添加到可绘制文件夹中。

喜欢:
透明.xml

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

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>
以酷 2024-09-09 12:22:00

对我来说 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.

楠木可依 2024-09-09 12:22:00

您只需要添加:
android:cacheColorHint="@android:color/transparent"

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

清晨说晚安 2024-09-09 12:22:00

作为替代方案:

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

listView.setSelector(new StateListDrawable());

As an alternative:

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

or

listView.setSelector(new StateListDrawable());
慕巷 2024-09-09 12:22:00

有一种快速而简单的方法可以做到这一点:
在方法中:

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

希望它会有所帮助;)

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 ;)

久伴你 2024-09-09 12:22:00

如果要禁用单个列表视图项的突出显示,但保持单元格启用,请设置该单元格的背景颜色以禁用突出显示。

例如,在单元格布局中,设置 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"

顾铮苏瑾 2024-09-09 12:22:00

您只需获取从 onItemClick 获取的 pos
并做:

listView.setItemChecked(pos, false);

这是我所知道的最好的方法

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文