64

How to make the ListView transparent in android?

The background android screen image should be visible.

Tamaghna M
  • 845
  • 2
  • 10
  • 10

11 Answers11

123

You should use the more verbose

android:background="@android:color/transparent"
android:cacheColorHint="@android:color/transparent"

Updated with Jacky's response. I originally merely meant to add to his answer, since he was using a plain hex color in the sample.

mxk
  • 43,056
  • 28
  • 105
  • 132
  • 3
    This is very late, but for people coming here, check out Jacky's answer below. Without setting android:cacheColorHint property, the result is very ugly. –  Jun 05 '11 at 02:02
  • That's because you should _not_ use the "more verbose". Matthias basically ripped off Jacky by stealing his answer and adding a superfluous piece of complexity. Essentially @android:color/transparent == #00000000 , the only difference is that instead of having the static hex value already the compiler has to look up that resource and insert the value itself. – Justin Buser Apr 17 '12 at 01:46
  • 5
    Good coding practices suggest you should use the platform setup value. If someone were to come back to it in the future, reading the above version would make more sense and indicate that the intention is clearly transparency. – Hamid May 17 '12 at 16:22
  • Sometimes one of item's background becomes black. – sagus_helgy Apr 23 '13 at 06:29
60

android:background="@android:color/transparent" android:cacheColorHint="@android:color/transparent"

Amer Hadi
  • 277
  • 3
  • 15
Jacky
  • 1,645
  • 1
  • 14
  • 16
13
  • How to make the ListView transparent in android?

As Jacky mentioned, setting attributes for list view will do the job.

android:background="#00000000" 
android:cacheColorHint="#00000000"
  • The background android screen image should be visible.

In Android manifest file add following attribute to activity.

android:theme="@android:style/Theme.Dialog"
edorian
  • 38,542
  • 15
  • 125
  • 143
bhatt4982
  • 8,024
  • 2
  • 26
  • 18
4

try this:

list.setCacheColorHint(Color.TRANSPARENT);
nikki
  • 3,248
  • 3
  • 24
  • 29
4

Add this to make list items stay transparent when pressed:

android:listSelector="@android:color/transparent"
j0k
  • 22,600
  • 28
  • 79
  • 90
Denis
  • 41
  • 1
  • 2
4

This article helps explain the nuances of ListView in conjunction with a custom background - http://developer.android.com/resources/articles/listview-backgrounds.html

tl;dr - put this in the offending ListView's xml somewhere:

android:cacheColorHint="#00000000"

cornbread ninja
  • 417
  • 1
  • 6
  • 17
3

If you want to use partial transparency, this would help you while setting your color codes.

2 hex characters can be appended to any hex color code. The first 2 characters in an 8-digit hex color code represents its opacity in Android.

The 2 hex characters can range from 00 to FF. For example-

  • Normal opaque black hex- "#000000"
  • Fully transparent black- "#00000000"
  • Fully opaque black- "#FF000000"
  • 50% transparent black- "#80000000"

This way you can change any color to any level of transparency.

Source- http://zaman91.wordpress.com/2010/03/22/android-how-to-create-transparent-or-opeque-background/

Aaron
  • 2,070
  • 1
  • 15
  • 9
3

You can use these

android:background="@android:color/transparent"
android:listSelector="@android:color/transparent"
Christoph
  • 47,569
  • 8
  • 87
  • 187
Kailas
  • 3,173
  • 5
  • 42
  • 52
1

try this:

android:cacheColorHint="@null"
romanzah
  • 21
  • 2
1

The answers above will work, but there is a chance that when you'll scroll the listView, it will darken, like in this case: android-listview problem with transparent cells

To solve the issue, you can use the cacheColorHint as mentioned above, but if you add the ListView dynamically (from code, not xml), then this will not work. You are forced to declare the ListView in XML, dunno if this is a bug or something else.

Community
  • 1
  • 1
XMight
  • 1,991
  • 2
  • 20
  • 36
0

Check this blog.

[http://aboutyusata.blogspot.in/2013/10/how-to-make-listview-with-transparent.html][1]

or

android:background="@android:color/transparent"
Avinash Jain
  • 261
  • 3
  • 4
  • I've posted a solution here: http://stackoverflow.com/questions/16560448/android-transparent-colored-listviews-with-background/38368774#38368774 – user2288580 Jul 14 '16 at 08:09