lomza
lomza

Reputation: 9716

Disable Android list view 'blue' background

When I click on the list item in Android, I always get a blue background. Event if I use a custom layout, when I click, maybe 2-5dp space around my layout is blue. Also, the text views get darker. How can I disable any changes in view when clicking on the list item?

Upvotes: 5

Views: 4786

Answers (5)

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

Use this

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

For more details you can visit here

http://developer.android.com/reference/android/widget/ListView.html

Upvotes: 3

aelahmar
aelahmar

Reputation: 26

I did it Like this:

<ListView
    android:listSelector="@android:color/transparent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
/>

Upvotes: 0

Anand Sainath
Anand Sainath

Reputation: 1807

I know its kind of late, but one can also use the setSelector method of the listview and set it to android.R.color.transparent. You can also use android:listSelector in the layout file to achieve the same result.

Upvotes: 5

Cata
Cata

Reputation: 11211

You can simply set the android drawSelectorOnTop attribute to false on your ListView and there will not be any background when you click on an item.

Eg:

<ListView android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:drawSelectorOnTop="false"/>

Upvotes: 3

peceps
peceps

Reputation: 17557

Create custom theme for your application in /res/values/themes.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>

  <!-- application theme -->
  <style name="CustomTheme" parent="android:style/Theme.Light">

    <!-- widget styles -->
    <item name="android:listViewStyle">@style/ListView</item>
  </style>

  <!-- list view -->
  <style name="ListView" parent="@android:style/Widget.ListView">
    <item name="android:background">#ffffff</item>
    <item name="android:cacheColorHint">#ffffff</item>
    <item name="android:divider">#cccccc</item>
    <item name="android:dividerHeight">1px</item>
    <item name="android:listSelector">@drawable/list_selector_background</item>
    <item name="android:fadingEdge">none</item>
  </style>

</resources>

In your AndroidManifest.xml specify the theme:

<application
    ...
    android:theme="@style/CustomTheme" >

Upvotes: 3

Related Questions