Android: Disable highlighting in GridView
Asked Answered
D

8

66

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

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

Divider answered 19/5, 2010 at 13:2 Comment(1)
Related: "Disable Android GridView highlighting completely (disable selection)" if you want to disable not just highlighting but selection and use the GridView just for layout, or handle selection manually via onTouch/Click/etc listeners.Nordic
A
146

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

Aerosphere answered 19/5, 2010 at 13:50 Comment(4)
On listviews android:listSelector="@null" does the trick but on gridview that wont work. But setting it transparent does work =/Mestizo
Note that elements of the selected view may still change in response to selection (e.g., TextViews changing to their "selected" color state). See this answer for how to disable selection entirely.Nordic
You can use android:listSelector="@android:color/transparent" if you are afraid of numbersSacrilege
Hi @Aerosphere , can you pls help.. I have a grid view with image as a single item in grid When I m clicking in space left around image ,I get touch feedback from gridview but no feedback on clicking on the image.. what can I do? thanks.Viscera
G
37

Another option is to reference the transparent color via @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"
/>
Glary answered 13/10, 2011 at 23:42 Comment(0)
A
19

I did the same thing in code using

GridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
Almaalmaata answered 2/6, 2010 at 17:26 Comment(0)
W
11

Add this property to gridview

android:listSelector="@android:color/transparent"
Willwilla answered 20/5, 2014 at 4:55 Comment(0)
B
7
<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 :)

Beset answered 25/4, 2013 at 10:28 Comment(1)
to hide highlighted from gridview.Beset
V
5

Try It...

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

Veilleux answered 20/2, 2017 at 10:16 Comment(0)
S
0

Just set below property in your XML file.

android:focusableInTouchMode="false"
Surmise answered 8/5, 2013 at 8:37 Comment(0)
U
0

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

<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" />
Unintelligent answered 10/5, 2016 at 5:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.