How to make a ListView transparent in Android?
Asked Answered
H

11

64

How to make the ListView transparent in android?

The background android screen image should be visible.

Hindgut answered 4/9, 2009 at 5:11 Comment(3)
Can you please mark the correct answerRomish
Please mark which answer is correct, as its very useful question..Mawkin
The best way you will find it on: nikshits.wordpress.com/2011/11/29/…Jaredjarek
T
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.

Taishataisho answered 7/9, 2009 at 7:49 Comment(4)
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.Marvel
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.Barolet
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.Linares
Sometimes one of item's background becomes black.Viewpoint
D
60

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

Dallis answered 4/9, 2009 at 9:46 Comment(2)
For a more detailed explanation: android-developers.blogspot.com/2009/01/…Cinquefoil
Why not use @android:color/transparent instead #00000000?Jandel
Z
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"
Zoltai answered 4/9, 2009 at 14:0 Comment(1)
Why not use @android:color/transparent instead #00000000?Jandel
G
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"

Goosander answered 12/9, 2011 at 18:51 Comment(1)
Why not use @android:color/transparent instead #00000000?Jandel
J
4

try this:

list.setCacheColorHint(Color.TRANSPARENT);
Jp answered 31/8, 2012 at 10:22 Comment(0)
T
4

Add this to make list items stay transparent when pressed:

android:listSelector="@android:color/transparent"
Tennison answered 10/9, 2012 at 11:50 Comment(0)
E
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/

Elvinelvina answered 30/5, 2013 at 8:19 Comment(0)
H
3

You can use these

android:background="@android:color/transparent"
android:listSelector="@android:color/transparent"
Harness answered 19/9, 2013 at 11:0 Comment(0)
D
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.

Dissertation answered 21/11, 2011 at 16:38 Comment(0)
I
1

try this:

android:cacheColorHint="@null"
Instalment answered 24/11, 2012 at 3:18 Comment(0)
H
0

Check this blog.

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

or

android:background="@android:color/transparent"
Habitant answered 8/1, 2014 at 7:36 Comment(1)
I've posted a solution here: #16560948Redound

© 2022 - 2024 — McMap. All rights reserved.