Android:在 GridView 中禁用突出显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2865683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:39:29  来源:igfitidea点击:

Android: Disable highlighting in GridView

androidgridviewclickhighlighting

提问by Impression

How can I turn off the orange highlight when clicking an item in a GridView?

单击 GridView 中的项目时,如何关闭橙色突出显示?

I haven't been able to find a solution in the documentation or through testing.

我一直无法在文档中或通过测试找到解决方案。

回答by CommonsWare

Use android:listSelector="#00000000"in your GridViewelement in your XML layout file.

android:listSelector="#00000000"GridViewXML 布局文件中的元素中使用。

回答by posit labs

Another option is to reference the transparent color via @android:color/transparent

另一种选择是通过@android:color/transparent 引用透明颜色

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/grid"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:listSelector="@android:color/transparent"
/>

回答by Matt

I did the same thing in code using

我在代码中做了同样的事情

GridView.setSelector(new ColorDrawable(Color.TRANSPARENT));

回答by Nayana Priyankara

Add this property to gridview

将此属性添加到 gridview

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

回答by Mohammed Saleem

<GridView
            android:id="@+id/gridView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:horizontalSpacing="10dp"
            android:listSelector="#00000000"
            android:numColumns="3"
            android:scrollbars="none"
            android:stretchMode="columnWidth"
            android:verticalSpacing="10dp" />

Done! this is a solution. thank you :)

完毕!这是一个解决方案。谢谢你 :)

回答by Android Devloper

Try It...

尝试一下...

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

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

回答by Pacific P. Regmi

Add android:listSelector="#00000000"or android:listSelector="@android:color/transparent"in your GridView XML element like bellow.

添加android:listSelector="#00000000"android:listSelector="@android:color/transparent"在您的 GridView XML 元素中,如下所示。

<GridView
        android:id="@+id/gridView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:columnWidth="150dp"
        android:gravity="center"
        android:listSelector="#00000000"
        android:numColumns="auto_fit"
        android:stretchMode="columnWidth" />

回答by RBL

Just set below property in your XML file.

只需在您的 XML 文件中设置以下属性。

android:focusableInTouchMode="false"