Search code examples
androidlistviewandroid-listviewclickable

ListView element - blue highlight


When I click or hold on one of items in my ListView then it's getting highlighted in blue. How can I disable it? I don't want any highlight.

My .xml file containing ListView:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/TableLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"  >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="10dp" >
    </ListView>

</TableLayout>

.xml for ListView items:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:background="#EC7703"
        android:padding="3dp" >

        <TextView
            android:id="@+id/lessonHoursTitle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="7dp"
            android:layout_weight="1"
            android:text="8.00-9.30"
            android:textSize="16sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/lessonTitle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:text="Mechanika ogólna"
            android:textSize="18sp" />
    </TableRow>
</TableLayout>

I've tried putting this on ListView but it doesn't work:

android:clickable="false"
android:contextClickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:longClickable="false"

Solution

  • On your ListView element you need to override the listSelector attribute.

    Something like this:

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:listSelector="@android:color/transparent"
        android:layout_marginTop="10dp" >
    </ListView>