Disable Android list view 'blue' background
Asked Answered
D

5

5

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?

Dominus answered 12/1, 2012 at 15:24 Comment(3)
When I click on the list item in Android, I always get a blue background. blue background for what? the listView or the listView item you're clicking?Panter
the list view item I'm clicking.Dominus
Can you edit your question with your problem(s) specified clearly? From what I understand, I believe you're mentioning three different problems. Can you explain each one clearly?Panter
F
3

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" >
Faxun answered 12/1, 2012 at 15:48 Comment(0)
V
5

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.

Volney answered 2/4, 2013 at 16:57 Comment(0)
F
3

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" >
Faxun answered 12/1, 2012 at 15:48 Comment(0)
B
3

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"/>
Bramante answered 12/1, 2012 at 15:52 Comment(3)
just adding this attribute didn't helpDominus
I even add a selector for states pressed, selected, focused, but this also didn't help...Dominus
And are you sure you don't have some selector on your item layout that you are adding on the list?Bramante
S
3

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

Stoops answered 16/5, 2015 at 7:34 Comment(0)
G
0

I did it Like this:

<ListView
    android:listSelector="@android:color/transparent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
/>
Gynaecomastia answered 15/7, 2014 at 9:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.